Go to Post How is it that so many team representatives have the time to run up the post count to astronomical levels in a game hint thread, while so few seem to have the time to say thank you for a $6K gift that funds the ability to play the game? - Rich Kressly [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-12-2005, 13:36
complete's Avatar
complete complete is offline
Registered User
no team
 
Join Date: Dec 2005
Location: Saint Louis
Posts: 6
complete is an unknown quantity at this point
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.
  #2   Spotlight this post!  
Unread 27-12-2005, 14:18
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
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.
__________________
http://www.mikesorrenti.com/
  #3   Spotlight this post!  
Unread 27-12-2005, 16:31
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
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).
__________________

  #4   Spotlight this post!  
Unread 27-12-2005, 17:28
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
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.
  #5   Spotlight this post!  
Unread 27-12-2005, 19:24
Timothy D. Ginn's Avatar
Timothy D. Ginn Timothy D. Ginn is offline
I check here maybe once a year.
no team
 
Join Date: Apr 2003
Rookie Year: 2002
Location: Port Perry, ON. Canada
Posts: 247
Timothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to allTimothy D. Ginn is a name known to all
Send a message via ICQ to Timothy D. Ginn Send a message via AIM to Timothy D. Ginn Send a message via MSN to Timothy D. Ginn Send a message via Yahoo to Timothy D. Ginn
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).
__________________
Alumni of FRC Team 1006
Former mentor of Full Lego Alchemist (FLL 5621) - Sempar School / Computing Students' Association of Queen's University
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Negative numbers? Calvin Programming 6 09-02-2005 10:46
Error in header file p18f8520.h !!! RbtGal1351 Programming 3 17-01-2005 16:03
heres the code. y this not working omega Programming 16 31-03-2004 15:18
File Sharing and Revision Tracking Madison FIRST-related Organizations 14 04-06-2003 18:01


All times are GMT -5. The time now is 16:11.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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