Sign in to follow this  
Followers 0
roofninja

string has no value

5 posts in this topic

I can't figure out a way to make this statement work. If $roomst[3] has no value or is not valid then $make = "MISSING". The program keeps dieing(like it should) for an error in the array. I am trying to find a way to say if you don't get anything then the information is missing. I am stuck. Thanks for the help.

$roomst = StringSplit(string("test-G1B3G01"),"-");@computername - "test-G1B3G01-g"
if StringInStr($roomst[3],"",0,1) = 0 then 
    $make = "MISSING"
elseif StringInStr($roomst[3],"D",2,1) then
    $make = "Dell"
elseif StringInStr($roomst[3],"I",2,1) then
    $make = "IBM "
elseif StringInStr($roomst[3],"G",2,1) then
    $make = "Gateway"
endif

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites



The sample string you provided ("test-G1B3G01") only gets split into 2 parts giving you this array:

[0] = 2

[1] = "test"

[2] = "G1B3G01"

But in your comment you have this string ("test-G1B3G01-g"):

[0] = 3

[1] = "test"

[2] = "G1B3G01"

[3] = "g"

See the difference?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

What about something like this

$roomst = StringSplit(string("test-G1B3G01"),"-");@computername - "test-G1B3G01-g"
if $roomst[0] >= 3 Then
Select
    case $roomst[3] = "D"
    $make = "Dell"
case $roomst[3] = "I"
    $make = "IBM"
case $roomst[3] = "G"
    $make = "Gateway"   
case Else
    $make = "Missing"
EndSelect
Else
    $make = "Missing"
EndIf
Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

The sample string you provided ("test-G1B3G01") only gets split into 2 parts giving you this array:

[0] = 2

[1] = "test"

[2] = "G1B3G01"

But in your comment you have this string ("test-G1B3G01-g"):

[0] = 3

[1] = "test"

[2] = "G1B3G01"

[3] = "g"

See the difference?

Yes thank you for pointing that out. I am trying to find a way to make the program work when the computer name is not to standards. Everybody makes a mistake every now and then. I have to thank you for getting me to see something different. I think I have found an answer to my question.


RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites

What about something like this

$roomst = StringSplit(string("test-G1B3G01"),"-");@computername - "test-G1B3G01-g"
if $roomst[0] >= 3 Then
Select
    case $roomst[3] = "D"
    $make = "Dell"
case $roomst[3] = "I"
    $make = "IBM"
case $roomst[3] = "G"
    $make = "Gateway"   
case Else
    $make = "Missing"
EndSelect
Else
    $make = "Missing"
EndIf

I need to be sure it works for both upper case and lower case, so I ended up with this.

if ($roomst[0] == 3) then 
    if StringInStr($roomst[3],"D",2,1) then
        $make = "Dell"
    elseif StringInStr($roomst[3],"I",2,1) then
        $make = "IBM "
    elseif StringInStr($roomst[3],"G",2,1) then
        $make = "Gateway"
    Else
        $make = "MISSING"
    endif
Else
    $make = "MISSING"
endif

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0