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
Solved

Get and Put, Again

Posted on 2000-03-15
4
129 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

840 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