Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get and Put, Again

Posted on 2000-03-15
4
Medium Priority
?
134 Views
Last Modified: 2010-05-02
Ok, i have some code and I have no idea whats wrong with it.

Private Sub Command1_Click()
Open "RSR" For Binary As #1
file4 = "Ding"
Put #1, , file4
Get #1, , file3
Close #1
RichTextBox2.Text = file3
End Sub

I checked and the put statement works, but the get statements reads the file and comes out with a null string.  When you look at the file in notepad it does say "Ding".  By the way, all the file3 and file4 are declared as strings.  Thanks for the help.
0
Comment
Question by:Shackman
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2619722
To read a string variable using Get you will need to dimension the string first, this can be done using Space$(length_of_string). The Get statement will then read length_of_string characters and put it into the string.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2619732
To show a example...

   Private Sub Command1_Click()

      Open "RSR" For Binary As #1
      file4 = "Ding"
      Put #1, , file4
      Seek #1, 1
      file3 = Space$(4)
      Get #1, , file3
      Close #1
      RichTextBox2.Text = file3

   End Sub

This code will load the "Ding" string into file3, probably what you tried to do.
0
 

Expert Comment

by:cdloves
ID: 2621429
When you first open the RSR file, it is blank.  After you Put the file4 in, the RSR will contain "Ding".  Because you did not close or reset the cursor back to the beginning, the cursor will be point after the char "g".  If you try to read in file3, you will get a null string because there is no other string after "Ding".  To retrieve the string "Ding", first close the file, then open again and read.

The "Seek" command in VBmaster could work as it looks like will (I never try that before though) reset the cursor to the beginning .

Hope this will give you a general idea what happened.

cdloves
0
 
LVL 9

Accepted Solution

by:
GivenRandy earned 100 total points
ID: 2783308
Yes, Seek is the way to got and it is fast.  I can Seek from beginning to end, or any point in between, of a 100 MB file in a fraction of a second.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

972 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