There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
VB 6 Reading from a sequential file....


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Justinl's Avatar
Member with 81 posts.
 
Join Date: Apr 2004
Location: Maine
08-May-2005, 12:47 AM #1
Solved: VB 6 Reading from a sequential file....
Hey all, I'm trying to read numbers from a sequential data file using Visual Basic 6.0. This is all I got so far, but everytime I run it all the data on the form turns into zeroes... Am I not defining a variable correctly or something? I'm pretty sure the data file is set up correctly with commas and all.
Any help is appreciated!

Dim strName As String, sngHomework As Single, sngProgram1 As Single, sngProgram2 As Single, sngProgram3 As Single, sngMidterm As Single, sngFinal As Single
Open "C:\Grades.dat" For Input As #1
Do While Not EOF(1)
Input #1, strName, sngHomework, sngProgram1, sngProgram2, sngProgram3, sngMidterm, sngFinal
Select Case strName
Case "Anne"
txtHomework.Text = sngHomework
txtProgram1.Text = sngProgram1
lblScore.Caption = Val(sngHomework + sngProgram1)
End Select
Loop
Close #1

I abbreviated the select case just to save space.
So far every text box on the form just has zeroes!
Thanks in advance!

Last edited by Justinl : 08-May-2005 06:40 PM.
MustBNuts's Avatar
Senior Member with 1,930 posts.
 
Join Date: Aug 2003
Location: Nevada
08-May-2005, 08:45 PM #2
The best thing to do is to step through your code. You can do this by putting a brown dot just to the left of, say, the Select Case, in the border area there. When you run the program, it will stop there.

But before you do, go to View and click on Immediate Window and a box will appear, possibly anchored to the bottom of the screen (if it isn't, this is a good a place as any to anchor it). Now right click up in the top, blank area of your toolbar, and make sure Debug is checked. Here, if you mouse over, you will see a button saying Step Into.

Now, with all this done and the brown dot notating where you want the program to stop, run it. When it stops at your select case line, you can, line by line, walk through the code. As you go line to line, that particular line is not executed until you step past it.

When you get to txtHomework.text = sngHomework, down in the Immediate Window you can query the value of sngHomework by typing ?snghomework and hit enter. If it has a value, it will print it out for you. If the value is null or incorrect, you have identified your problem or isolated where the error might be.

You might want to start by stopping on your Do While and making sure, at the very beginning, that you aren't already at EOF....

Have fun,

MBN
__________________
I'll burn that bridge when I get to it!
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 6,370 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
09-May-2005, 06:38 AM #3
Another alternative is to put this -
msgbox strName & " " & sngHomework & " " & sngProgram1 & " " & sngProgram2 & " " & sngProgram3 & " " & sngMidterm & " " & sngFinal

between your Input #1 line of code and your Select Case.
This will print out in a message box anything that is returned from your file.
You should also be able to open your file using wordpad to see if it structured correctly.
__________________
.
.
OBP
I do not give up easily
MustBNuts's Avatar
Senior Member with 1,930 posts.
 
Join Date: Aug 2003
Location: Nevada
09-May-2005, 10:06 PM #4
Yup, you're right OBP. I chose to explain stepping through the code because when I first learned, I got through an entire semester of VB and the instructor never showed us! Once you work with it, it's invaluable.

but if justin comes back to read, both will tell you what your inputs are and then you can step through to make sure that your textbox is getting assigned appropriately.

Let us know how you make out,

MBN
__________________
I'll burn that bridge when I get to it!
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:23 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.