Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   reading negative numbers from a file in VB (http://www.chiefdelphi.com/forums/showthread.php?t=41040)

complete 27-12-2005 13:36

reading negative numbers from a file in VB
 
So far the code I have written can read and write to and from a file.

In other words, I have the
Code:

    Line Input  #FileNum...
and the
Code:

    Write #FileNum...
written.

But how do I handel a situation where the file has negative numbers to be read? I am able to output to a file a negative integer. But when I try to read it back I get an error.
I assume I will have to read each line of the file one by one into a string and then have it converted. What are the string conversion routines in VB? The line of code is written as

-1

I suppose I have to do some string manipulation to get it stored back as a negative integer.

Mike 27-12-2005 14:18

Re: reading negative numbers from a file in VB
 
http://www.chiefdelphi.com/forums/sh...ad.php?t=29944
Replace Delphi with your programming language of choice (minus PIC C)

This is not a general programming website. We are for the FIRST robotics competition.

Ryan M. 27-12-2005 16:31

Re: reading negative numbers from a file in VB
 
Although we can try to help. ;)

I don't know VB worth crap, so there could be an easier way, but I'd say that you could check if it begins with a '-,' strip it off if it does, convert the main part to a number, then multiply by -1.

IE, if you have "-5" in a file, you take off hte negative ("5"), convert it to a number (5), then multiply by -1 (-5).

Astronouth7303 27-12-2005 17:28

Re: reading negative numbers from a file in VB
 
If you're using the Write # statement, you should use Input #, not Line Input #.

Otherwise, VB is very good about preserving data.

Timothy D. Ginn 27-12-2005 19:24

Re: reading negative numbers from a file in VB
 
I believe the string conversion routine you're looking for is:

val()

It'll convert a string to a number.

The opposite is:

str()

(which converts a number to a string).


All times are GMT -5. The time now is 22:01.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi