Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,453 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,982 people online right now. Registration is fast and FREE... Join Now!




file processing in visual basic

 
Reply to this topicStart new topic

file processing in visual basic, read from file

renoald
27 Jul, 2008 - 01:49 AM
Post #1

New D.I.C Head
*

Joined: 27 Jul, 2008
Posts: 1

i have problem with visual basic programing! i want read data from txt file and do the calculation!.
Below is my txt fle(in notepad):

#Cerapan Jarak
D 1-2 9999.030 0.038
D 2-3 9998.030 0.038
D 1-3 14142.110 0.094

#Cerapan sudut
A 1-2-3 44-59-19 2.4
A 2-3-1 90-01-22.1 2.4
A 3-1-2 44-59-18.1 2.4

#Cerapan Azithmuth
B 3-1 225-00-15 1
B 1-2 00-00-58 1

#Koordinat stesen
c 1 10000.0000 10000.0000 ! !
c 2 10002.7140 19998.0000
c 3 20000.7140 19999.2600

Problem:
when meet character "#", skip the line
-How to skip the line in VB?

Value n=8, where 3 char A ,2 char B and 3 char B
how to read from file and find how many character A,B and D?

how to get value 9999.030 and 0.038 from file?
9999.030 and 0.038 to become double that use in calculation!
any can idea to resolve this problem?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: File Processing In Visual Basic
27 Jul, 2008 - 01:58 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,462



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
When you read in your string, test it with InStr, which will return the position in the string where the character is found. If it has a value other than zero, then don't keep it, or basically drop it. If it has a zero value, then # is not in the string, so process it.

vb

' String to search in.
Dim SearchString As String = ""

' Fill SearchString with the line from the file
TestPos = InStr(1, SearchString, "#")
If TestPos > 0 Then
' Drop this string
End


I hope this helps, as I am very rusty with VB.
User is online!Profile CardPM
+Quote Post

adw888
RE: File Processing In Visual Basic
27 Jul, 2008 - 02:16 AM
Post #3

New D.I.C Head
*

Joined: 10 Jul, 2008
Posts: 17



Thanked: 1 times
My Contributions
Looking at your file, the easiest way would probably be to use the "Line Input" command to read each line individually into a string: http://www.dreamincode.net/code/snippet318.htm
Then you would just check the first character to see if it was a "#" and skip processing the line if so. If it isn't a comment line, then you could use the "Split" command and break the string up according to where the spaces are. Once you've split up the string, the first substring will hold "A", "B", "c", or "D" while the third and fourth (for the "D" lines) will hold the values for your calculation. You should just be able to assign those values into Double variables, but I'm not 100% sure about that part.

Hope this helps. smile.gif

EDIT: I just quickly tried what I've written above and it all works. I would post the code here but as you haven't posted any code of your own that would be against the rules if I remember correctly.

This post has been edited by adw888: 27 Jul, 2008 - 02:32 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:12PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month