Solved

Get and Put, Again

Posted on 2000-03-15
4
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

735 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