Solved

Open file problem

Posted on 2000-03-28
41
235 Views
Last Modified: 2010-05-02
i want to open an ini file in readwrite mode, when i open it in for output or for input it accept only it type and not allow me to read write
what can i do
0
Comment
Question by:ackid32
  • 10
  • 10
  • 7
  • +5
41 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Open "TESTFILE" For Binary Access ReadWrite As #1
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
ackid32:

Last 10 Grade(s) Given:  
A A B B B B B C B D  
Question Grading Record:  
16 / 19  

0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
>>when i open it in for output

When you open a file FOR OUTPUT, it's contents is destroyed, this is:
a) if file doesn't exist, a new file is created
b) if file exists, the file is deleted; then proceed as in a)

OPEN FOR OUTPUT is used when you want to create a file ONLY, not to read an existing file.
0
 

Expert Comment

by:AshokKumar
Comment Utility
Here is one alternate method ackid32. Declare two API functions namely

GetProfileString Or GetPrivateProfileString

And WriteProfileString Or WritePrivateProfileString

U can just pass the Filename, KeyValue and fulfill your needs. Just use GetProfileString to Read data and WriteProfileString to write Date.

<Smile>  Get back to me.
0
 
LVL 1

Expert Comment

by:prem_kumar_25
Comment Utility
For opening and modifying an  ini file u have to use the api function's GetPrivateProfileString And WritePrivateProfileString respectively for reading and writing info's into an INI file this is available in the File Win32api.txt
under the Program Files \Devstudio\VB\Winapi

When u open this with the Api file viewer u can see the parameters

Thanking U

Cheer's

Prem
0
 

Expert Comment

by:AshokKumar
Comment Utility
Hold on moment. Prem_Kumar_25 has given the same answer as me but he gets the points. how come. Come on ackid32
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
AshokKumar,

My heart bleeds for you, but if you had read the comments made by wsh2 and me you would have known that ackid32 is not the most decent of contributors to this site.
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
caraf_g:
How did ackid32 and the word decent get into the same sentence? Ah, now I see.. it was a spelling error.. you meant de-scent.. as in something smells in de-ghetto.. LOL.
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
It must be nice to be a duck. We're water.
0
 

Expert Comment

by:AshokKumar
Comment Utility
Thanks guys. caraf_Q and wsh2.  Indeed prem needs points desperately it seems. Not my problem really. Right?? Anyway caraf. U have guided me evertime i err. Thanks friend.
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Thanks AshokKumar, I know I can sound like a grumpy old man sometimes but I mean well ;-)
0
 

Author Comment

by:ackid32
Comment Utility
Hi, thanks all, i want to open a file to read write simultaneously, i dont want the api calls.
please!
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
AshokKumar writes "Thanks guys. caraf_Q"
And then writes: "Anyway caraf."

AshokKumar.. it is spelled caraf_g.. do I get to be a guide now too?.. <lol> and a <wink>.

-------------------------------------
caraf_g writes: "I can sound like a grumpy old man"

You ARE a grumpy old man... <laughing>.. bet you can't wait for the EE server to crash again.. <sheesh>.

(Now writing note to Linda.. I left a comment about how caraf_g is a very talented, well respected professional.. but for some reason it now reads grumpy old man?.. Wazzup? Please have an engineer look into this).. <wink>.

-------------------------------------
One last word.. AshokKumar, caraf_g is everything that you believe him to be.. only Better.. <smile> and a <wink>.
0
 

Expert Comment

by:AshokKumar
Comment Utility
U sound pretty good to me caraf. And for you ackid, files can be opened in three modes onlly.

Read (Read-Only)
Write (Write-Only)
Append (Write That be added to an existing file)

I don't know any other method.
0
 

Author Comment

by:ackid32
Comment Utility
Because i make sure that no one can acces that while i open it
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
ackid32 writes: "i want to open a file to read write simultaneously, i dont want the api calls"

Follow the code closely..

Open http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10318577
Pay.Points

Open http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10316154
Pay.Points

Open http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10316153
Pay.Points

Open http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10309119
Pay.Points

Open http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10297284
Pay.Points

and then everything will be ALL...
WRITE

<smile> and a <wink>

0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
wsh2, do you ever watch "One foot in the grave"? I'm Victor Meldrew. <g>

Hi ackid32, thanks for following up. Can I ask you something... Your question history is not very promising; you don't give very good grades and you've occasionally left answered questions hanging in limbo causing them to be autograded. I hope you intend to improve on that record?

The api calls are a good way of achieving what you need. Why not use them?
0
 

Expert Comment

by:AshokKumar
Comment Utility
wsh2. Are u a debugger or what. U seem to find some error in any one's comment. Good for me and for others also. I feel we need a guy like u.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:Ark
Comment Utility
Wsh2,
It should be Points.Pay (object first, method second) or Pay(Points) - Function first, argument - second :-)
Cheers
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
AshokKumar:
Contrary to what caraf_g wrote.. Do you ever watch "One foot in the grave"? I'm Victor Meldrew.. <LOL>.

Trust me.. All is written with good intent and with tongue in cheek.. I bought my copy of VB in the humor section of the store.. <smile> and a <wink>.


0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
Ark:
ROFLMAO.. well keyed !!!
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Guess that's the risk you take when you try to lighten up a thread with a bit of humour - sometimes it can be taken the wrong way. AshokKumar, I've dealt with wsh2 in a few threads so far and my impression is that wsh2 is a decent guy/gal. So I would like fo you people to kiss and make up now!
0
 

Author Comment

by:ackid32
Comment Utility
hi, this is problem i have faced in experts-exchange, that nobody told me the right way to solve my problem and ask for points. Take this question
1. i want to open a file in readwrite mode
2. nobody access that file while i do operations in that file

wsh2 don't see any ones history, also the question & answers. i honestly ranked them and accept those which are ok to "ME" and not to you the nuts. Do you think that you are an expert, idiot, behave like a gentleman, acceptance or reject is up to me and i follow it geniunly. 16/19 is not a bad one and not i gave A & B grades also.
Thanks all except wsh2
0
 

Expert Comment

by:AshokKumar
Comment Utility
caraf. I said in a friendly tone. I have no probs. with wsh2 <Smile> He/She only brightening things up. ackid32. Don't be so rude to wsh2.
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
ackid32 writes: "hi, this is problem i have faced in experts-exchange, that nobody told me the right way to solve my problem"

In the five questions you left unanswered.. a whole bunch of "nuts" went through a whole bunch of effort and kindly answered you.. with some VERY correct answers I might add! After all that, at the end of these threads, you never even take a moment to explain why the answers are lacking <we EE idiots do like to know.. duh.. lol>.. or even go so far as to extend a Thank You. As you say, I may be a nut and an idiot.. but at least I can say I am not ingracious or rude.. <smile>.

Uh, just for a moment ackid32, did you ever think.. it just might be you?.. <smile> and a <wink>.
0
 

Expert Comment

by:AshokKumar
Comment Utility
caraf. I said in a friendly tone. I have no probs. with wsh2 <Smile> He/She only brightening things up. ackid32. Don't be so rude to wsh2.
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
AshokKumar:
I found your comments most well intended.. no offense, or thought of it, was ever taken. I very much look forward to working with you in the future.. <smile>. caraf_g is just trying to start trouble.. LOL.. Just kidding !!!
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
Oh.. and by the way.. in the spirit of EE.. ackid32 maintains that the 5 open questions I alluded to earlier in my comment.. are in need of answering!!!
Check them out.. hear?

Let me know if you can find a better answer to his questions. I mean, assuming that you are NOT a nut / idiot like me.. it should be easy to do.. right ackid32?.. <smile>.
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
<hands out happy pills>
C'mon people. Peace. Stick flowers in your hair. Dance in the meadows. Visit Haight-Ashbury. Put on your favourite Woodstock album and sing along. Smoke a joint if that's what it takes to make you mellow.... Grrrrooooovey....
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Don't forget do don your flowery robe
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
caraf_g:
<sighing heavily and remembering the 60s>.. Yes caraf_g.. I suppose you are correct.. <now making a PEACE sign with his hand and smiling>.. Ooops.. I am an idiot.. sorry ackid32.. I'm supposed to put up my index finger with the other one too.. <LOL>.. Just kidding !!!! Its a joke.. <sheesh>.

caraf_g.. you ARE a trouble maker.. <wink>.
0
 

Author Comment

by:ackid32
Comment Utility
hi, i have visitors that time, i refused that answers( i state the reason there) and it is now unlocked, so why you blame me, try to answer that or left
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Now here's an interesting observation:

ackid32, if I remember correctly you accepted prem_kumar_25's answer, right?

Well, since then EE have moved offices, lost data, kept us all hanging about for a day.... and now, lo and behold, prem_kumar_25's answer is back to its proposed status....

Now, EE has promised that they'll try and restore the data. But I'd be very curious to see what happens if you now go and accept, say, AzraSound's comment as an answer.

Wonder what will happen if EE then comes along and tries to restore the data in this thread. It'd be an interesting experiment. Want to give it a try?
0
 
LVL 3

Accepted Solution

by:
vikiing earned 50 total points
Comment Utility
>>Read (Read-Only)
>>Write (Write-Only)
>>Append (Write That be added to an existing file)

Friend AshokKumar: If you open a file FOR BINARY or FOR RANDOM, you have read/write access to the file.

Just in the case you were working with SEQUENTIAL files only, then, yes, you would have the afm ways solely.

The problem is that a .INI file is a simple text file; thus, it can't be opened in other way than FOR INPUT/OUTPUT/APPEND, turning Ackid's desire into a dream (of course, FOR RANDOM/BINARY work with **ANY** file type, no matter its contents; but it's impossible to add any info to it).

Ackid: if you do not want to use the mentioned APIs for INI files handling, the only way you have to modify a .INI file is:
a) Load the whole file into a vector (or list), with an OPEN FOR INPUT
b) Search for the sction you want to modify
c) Add/modify lines according what you need
d) Re-create the file with its new contents, with an OPEN FOR OUTPUT

And definitely THERE'S NO OTHER WAY.

Anyway, ¿will you pay your points ANYONE this time?
0
 

Author Comment

by:ackid32
Comment Utility
i already said above, anybody?
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
Well, you've received a couple of satisfactory answers. You know what to do.
0
 

Author Comment

by:ackid32
Comment Utility
ok, i accept, thanks all, not to wsh2(nasama ponavan)
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
nasama ponavan?

Is that the same as lolbôks or is it something altogether more rude? :o)
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
Well, thanks for the points, and glad to have helped you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now