Results 1 to 10 of 10

Thread: [RESOLVED] VB Error

  1. #1

    Thread Starter
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95

    [RESOLVED] VB Error

    hey all,
    can anyone tell me what is wrong with this??
    VB Code:
    1. FileName = App.Path & "\Scores\High Score.cam"
    2.  
    3.     'get high scores from file
    4.     Open FileName For Input As 1
    5.     Do Until EOF(1)
    6.         Line Input #1, HScore.Name
    7.         Line Input #1, HScore.Score
    8.     Loop
    9.     Close #1

    in a code module, i have a Public Type which is where the HScore.Name and HScore.Score came from. when i try to run the program, it comes up with a mismatch error and when i click debug, it highlights the .Score part of HScore.Score


    thanks
    Last edited by DJ P@CkMaN; May 31st, 2002 at 10:33 PM.
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  2. #2
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273
    If Score is numeric you may need to convert it to a numeric value.

    FileName = App.Path & "\Scores\High Score.cam"

    'get high scores from file
    Open FileName For Input As 1
    Do Until EOF(1)
    Line Input #1, HScore.Name
    Line Input #1, Score$
    HScore.Score = clng(Score$)
    Loop
    Close #1

  3. #3

    Thread Starter
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    that sounds right because in the type, its

    Score As Integer

    thanx for the help
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  4. #4

    Thread Starter
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    i get an Overflow error. it highlights

    VB Code:
    1. HScore.Score = CLng(Score$)

    any ideas??
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  5. #5
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273
    Why are you using Line Input?

    Line Input reads the entire line in the file until it encounters a CR.

    If the file contains this data, for instance,

    Johnny, 1345
    Billy, 7890

    Line input would read the whole line - 'Johnny, 1345' into the first variable.

    Input would only read 'Johnny'

  6. #6

    Thread Starter
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    the file is

    Cameron
    100
    so i do line input, and line 1 goes into HScore.Name and the score goes into HScore.Score

    it works fine if i use plain strings instead of a public type, so i tried

    VB Code:
    1. Open FileName For Input As 1
    2. Do Until EOF(1)
    3.     Line Input #1, strName
    4.     Line Input 1, intScore
    5. Loop
    6. Close #1
    7.  
    8. HScore.Name = strName
    9. HScore.Score = intScore

    but i get an overflow error with that
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  7. #7
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273
    The overflow error on an integer data type is usually caused by being assigned a value greater than 32767.

    Are there any scores greater than that? If so, try using a Long Integer.

    HTH

  8. #8

    Thread Starter
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    the highest possible score is 120, but i will try changing it to Long and see if that makes a diff
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  9. #9

    Thread Starter
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    weird.. Long works perfectly.. oh well, thanx heaps for your help
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    You were trying to assign a CLng (a LONG conversion) to
    HScore.Score (prolly Dimmed an Integer).... So it would make
    sense that HScore.Score should be Dimensioned as a Long.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width