Page 1 of 1 1
Topic Options
#3448 - 2000-07-07 03:17 PM What is wrong with this - It is driving me mad
Anonymous
Unregistered


Hello,

I am working on a small script that will allow users to automatically add printers to their NT 4.0 W/S

I have for the last three days been tearing my hair out over the piece of code below. I have checked a number of example scripts and as far as I can see the IF statement looks fine.

Basically the user will be presented with a menu of printers they wish to add. They then select the number of the printer they wish to add.

This is the gets $sel statement.

The variable $new_count is equal to the number of printers to choose from, in this case 12.

So the logic should be if the choice is greater than or equal to 0 or less than or equal to 12, gosub the add_printer routine.

This actually works fine, the problem is if you enter a negative number, or a number greater than twelve. It still gosubs add_printer routine, does not matter what number, it tries to add a non-existant printer.

I have tried every permutation possible, I think. Being fairly new to Kix, I'm I missing something blindingly obvious.

I have the latest version 3.62 and I'm using v2.0 of the Visual editor.


? " "
color c+/n
? "Please Select Printer you Wish to Add : "
gets $sel


IF $sel >= 0 OR $sel <= $new_count

? $sel
gosub add_printer

Else

? $sel
? "Invalid Choice - Please Select 0 to " + $new_count
sleep 2

endif

Top
#3449 - 2000-07-07 03:50 PM Re: What is wrong with this - It is driving me mad
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
you need to use the AND operator not OR.

IF $sel >= 0 AND $sel <= $new_Count

Bryce

[This message has been edited by Bryce (edited 07 July 2000).]

Top
#3450 - 2000-07-07 04:21 PM Re: What is wrong with this - It is driving me mad
Anonymous
Unregistered


Yep, already tried that, this is where it starts to get weird and where I have been losing it.

If you change the statement to AND, User is presented with a menu listing thirteen printers numbered 0 to 12.

You can select 0 or 1 or 10 or 11 or 12, and the Gosub add_printer statement works, as it should.

However, if you select 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9, all of which should be valid choices, you get the Invalid choice message printed.

AArrrrgggghhhhhh

Top
#3451 - 2000-07-07 04:43 PM Re: What is wrong with this - It is driving me mad
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
You have run up against the great integer VS string battle

try adding this

code:

gets $sel
$sel = val("$sel")

and make sure that when you assign the $new_count variable that you do so without using quotes.

code:

$new_Count = 12

Bryce

PS. the latest chapter in the starters guide goes in to great detail about integers VS strings http://www.neosoft.com/~brycel/kix


Top
#3452 - 2000-07-10 06:40 AM Re: What is wrong with this - It is driving me mad
Anonymous
Unregistered


Yes......

That appears to have worked, thanks for the advice. Shall certainly remember that from now on...

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.108 seconds in which 0.052 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org