Author Topic: illeagal string-number conversion error  (Read 3800 times)

0 Members and 1 Guest are viewing this topic.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
illeagal string-number conversion error
« on: September 26, 2020, 03:41:06 pm »
Hello

can someone tell me why this is happening

have _defstr s
TYPE customer
        id AS LONG
        sfirst_name AS STRING * 25
        slast_name AS STRING * 25
        saddress AS STRING * 30
        scity AS STRING * 25
        sstate AS STRING * 2
        szip AS STRING * 5
        sphone AS STRING * 10
END TYPE


DIM custinforec AS customer


        s2: saction = "Enter Lase Name X to Exit - To Backup "
        ib = 25
        ilow = 99
        ihigh = 99
        iflag1 = 0
        CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        IF saction = "-" THEN GOTO s1
        IF saction = "X" THEN
                RETURN
        ELSE
                LOCATE 11, 24
                custinforec.sfirst_name=sr /the error is here/
                PRINT custinforec.first_name
        END IF

error is illaegal string-number conversion on line 287

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: illeagal string-number conversion error
« Reply #1 on: September 26, 2020, 04:38:17 pm »
Hi badger
from your stripped code I cannot see more...
but if I copy your code and paste it into QB64 IDE, after REMMED out the
Code: QB64: [Select]
  1. CALL salphainput
, and after type
Code: QB64: [Select]
  1.  s1:
label  and REMMED the C style comment
Code: QB64: [Select]
  1.  /the error is here/
  2.  
I get no issue... so I can think that the line of code that rises up the error of illegal string number conversion  is into a SUB or Function and not in the main or in a GOSUB.... in this case
Code: QB64: [Select]
  1. custinforec.sfirst_name
becomes a single variable...
but how to solve the question? Easy, make global shared the variable custinforec. How? Simply typing SHARED on the line of DIM custinforec... like this
Code: QB64: [Select]
  1. DIM SHARED custinforec AS customer
.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: illeagal string-number conversion error
« Reply #2 on: September 26, 2020, 04:51:32 pm »
Code: QB64: [Select]
  1. custinforec.sfirst_name=sr /the error is here/

So what is sr?

I can not duplicate the error unless sr = number.

I cannot set sr to number after DEFSTR S but before that I can.
« Last Edit: September 26, 2020, 05:02:48 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: illeagal string-number conversion error
« Reply #3 on: September 26, 2020, 04:53:39 pm »
If you got that right, without seeing the actual code where the error occurred, give yourself a prize!

To the OP: It's always best to post the entire code or at least all the code involved in the situation. For instance, if I had a program with 20 subs, but the error as only occurring in one of those subroutines, I'd copy the main, REM out the other sub calls, and copy that sub. Now, others could run the code, re-create the error, and hopefully enlighten me on why it didn't work correctly.

Now go in the kitchen and bake me a pizza. I might need it, to reward Tempo.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: illeagal string-number conversion error
« Reply #4 on: September 26, 2020, 04:57:04 pm »
Hello

salphinput is an all in one input statement the only one the software will have

sr is the line input statement variable sr handles all input then transfers it value to the proper variable after it checks the validity of the info being entered . I will try your suggestions

Badger

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: illeagal string-number conversion error
« Reply #5 on: September 26, 2020, 05:00:30 pm »
Hello

Pete i think he gave me the answer but i have yet to try getting ready to. i use a lot of rem statement above each sub /label to help me keep track of my code, I have problems seeing so do this people dont like the way it looks.

Badger

if what i hope fixes it i will post all


Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: illeagal string-number conversion error
« Reply #6 on: September 26, 2020, 05:08:26 pm »
Temopdibasic

Hello

I sorta thought it was something like that. I took out the type and just used the string veriables and all worked fine. I have not used subs in basic much even when i was using quick basic 4.5 i would recreate lables and gosub and goto them but from a common spot on in the problem. 

Thanks very very much for the help

Badger

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: illeagal string-number conversion error
« Reply #7 on: September 27, 2020, 12:19:21 pm »
badger
Welcome in QB64 community...
when you have finished your program post your final work with code or a screenshot of your final well working program in the section of programs
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: illeagal string-number conversion error
« Reply #8 on: September 27, 2020, 12:25:17 pm »
...And don't forget, you owe Tempo a pizza!

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: illeagal string-number conversion error
« Reply #9 on: September 29, 2020, 10:54:05 am »
Pete

That is fine with me LOL

Badger

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: illeagal string-number conversion error
« Reply #10 on: September 29, 2020, 03:39:15 pm »
I must affirm that half of the pizza is for Pete, so please ask him what kind of pizza does he like.
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: illeagal string-number conversion error
« Reply #11 on: September 29, 2020, 08:46:23 pm »
FREE PIZZA
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: illeagal string-number conversion error
« Reply #12 on: September 29, 2020, 08:48:32 pm »
I knew it! I saw that one coming LOL!