Jump to content



Photo

Variable Verification


  • Please log in to reply
6 replies to this topic

#1 Xonos

Xonos

    Seeker

  • Active Members
  • 44 posts

Posted 09 August 2012 - 01:07 PM

So I have been in and out of AutoIt for a few years now and I've never come across a situration where I'd need to verify if an a variable is an array or not.

So here's the deal - I have a database that contains 1 table with a few different columns. When a user initially opens the script, it will see if their "username" pulled from @UserName is stored in the database (which is always unique).

If their username is not in the database, it inserts a record (using EzMySql) including their username, full name (pulled from ->
_AD_Open()
Global $adFullName = _AD_GetObjectAttribute(@UserName, "DisplayName")
Global $uSName = @UserName
_AD_Close()

<-), Time Stamp, Accept Flag (0/1) and Deny Flag (0/1).

This is all irrelevant at this point but I just wanted you to understand what I am doing here.

Anyways, I am getting to the point to where I am storing specific values from the table into variables. EzMySql will store the data in an array (IF the query finds results) however if it does not, then the variable will not be an array.

The problem is, when I run my "If statements" - if I check the variable, there is no way for me to know if the results are stored in array format or not.


Here's an example, read the comment above $LookupUser.

Plain Text         
Func _CheckDatabase() ; Obtain user's Full Name and store as variable. If Not _EzMySql_Startup() Then     MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())     Exit EndIf $Pass = "D@#!$dD(#d0939kd(#Dk3093d)(#D039039ddk39dkd" If Not _EzMySql_Open("10.3.3.11", "rug_user", $Pass, "rug", "3306") Then     MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())     Exit EndIf If Not _EzMYSql_Query("SELECT * FROM accept_list WHERE Username = '" & @UserName & "';") Then MsgBox(0, "Query Error", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())     Exit EndIf If Not _EzMySql_SelectDB("rug") Then     MsgBox(0, "Error setting Database to use", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())     Exit EndIf $LookupUser = _EzMySql_FetchData() ;This is the problem - if there is no data found, $LookupUser[1] for example will not work returning an error. This function currently works but I need more functionality. If $LookupUser == 0 Then $sMySqlStatement = "INSERT INTO accept_list (Username,FullName) VALUES (" & "'" & $uSName & "'," & "'" & $adFullName & "');"     If Not _EzMySql_Exec($sMySqlStatement) Then         MsgBox(0, "Error inserting data to Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())     Exit EndIf ElseIf $LookupUser <> 0 Then     _CheckFlags()     ;Call function to verify if user has accepted or not. EndIf _EzMySql_Close() _EzMySql_ShutDown() Return EndFunc






#2 Scriptonize

Scriptonize

    Adventurer

  • Active Members
  • PipPip
  • 144 posts

Posted 09 August 2012 - 01:09 PM

Did you check the IsArray() function?
  • Xonos likes this
If you learn from It, it's not a mistake!WinServices

#3 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,831 posts

Posted 09 August 2012 - 01:33 PM

And also UBound() will help verifying arrays size.
  • Xonos likes this
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#4 Xonos

Xonos

    Seeker

  • Active Members
  • 44 posts

Posted 09 August 2012 - 02:28 PM

Did you check the IsArray() function?

And also UBound() will help verifying arrays size.

Thank you both - this solved my issue entirely! I tested it using the following and ensured that I had "
#include <Array.au3>
" included.:
If IsArray($LookupUser) Then MsgBox(0, "Variable Array Check", "Your variable is an array - hurray!") Else MsgBox(0, "Variable Array Check", "Your variable is not an array - awww.") EndIf


Thanks again guys!

#5 water

water

    ?

  • MVPs
  • 10,679 posts

Posted 09 August 2012 - 02:37 PM

#include <Array.au3>
is not needed to use function "IsArray". IsArray is part of AutoIt itself.
  • Xonos likes this

UDFs:

Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts

WordEX (2012-12-29 - Version 1.3 released) - Download

ExcelEX (2013-05-11 - Alpha 4 released) - Download


#6 Xonos

Xonos

    Seeker

  • Active Members
  • 44 posts

Posted 09 August 2012 - 02:43 PM

Gotcha! Thank you again for the quick replies and excellent service - without you guys, I'd have to write this all in Visual Studio.

#7 water

water

    ?

  • MVPs
  • 10,679 posts

Posted 09 August 2012 - 02:52 PM

Glad we could help :D
  • Xonos likes this

UDFs:

Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts

WordEX (2012-12-29 - Version 1.3 released) - Download

ExcelEX (2013-05-11 - Alpha 4 released) - Download





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users