Solved

Get and Put, Again

Posted on 2000-03-15
4
127 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

9 Experts available now in Live!

Get 1:1 Help Now