Jump to content


Photo

help with function


  • Please log in to reply
5 replies to this topic

#1 biatche

biatche
  • Members
  • 87 posts

Posted 13 August 2012 - 08:34 AM

CheckFields()
{
	Global
	If (!Comp)
	{
		MsgBox, Error: Workstation field empty
		return false
	}
	If (!Username)
	{
		MsgBox, Error: Username field empty
		return false
	}
	If (!Password)
	{
		MsgBox, Error: Password field empty
		return false
	}
	If (!Gateway)
	{
		MsgBox, Error: Gateway field empty
		return false
	}
}
return

GuiClose:
ExitApp

Scan:
gui, submit, nohide
If (CheckFields())
{
	MsgBox % CheckFields()
	run, %comspec% /k psexec.exe %Comp% -u "%UserName%" -p "%Password%" -s netsh interface ipv4 show route > c:\asdf.asdf
}
return

What am I doing wrong here? All I want is for it to call CheckFields function and if there's an empty field it will return something other than 0...

#2 HotKeyIt

HotKeyIt
  • Fellows
  • 6132 posts

Posted 13 August 2012 - 08:51 AM

:?:
;...



   If (!Gateway)

   {

      MsgBox, Error: Gateway field empty

      return false

   }

[color=#FF0000]   return 1[/color]

}

;...


#3 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 13 August 2012 - 08:55 AM

you call the function but never show where the fields like comp, username, etc are set. Without that information there is no way to answer your question. I would however, check the length of each of the strings to see if the lengths are greater than some lower limit. rather than just checking for a true or false. Unless, of course, you actually are looking for possible single character user names...

#4 biatche

biatche
  • Members
  • 87 posts

Posted 13 August 2012 - 09:33 AM

Gui, Add, Text,x16 y243 w90 h20, Username
Gui, Add, Edit,x106 y240 w110 h20 vUserName, %a_username%

That's an example of one of the fields, pretty straightforward.

HotKeyIt: Why return 1 there?

#5 biatche

biatche
  • Members
  • 87 posts

Posted 13 August 2012 - 09:38 AM

CheckFields()
{
	Global
	If (!Comp)
	{
		MsgBox, Error: Workstation field empty
		return 1
	}
	If (!Username)
	{
		MsgBox, Error: Username field empty
		return 1
	}
	If (!Password)
	{
		MsgBox, Error: Password field empty
		return 1
	}
	If (!Gateway)
	{
		MsgBox, Error: Gateway field empty
		return 1
	}
	return
}

GuiClose:
ExitApp

Scan:
gui, submit, nohide
If (!CheckFields())
{
	run, %comspec% /k psexec.exe %Comp% -u "%UserName%" -p "%Password%" -s netsh interface ipv4 show route > c:\asdf.asdf
}
return

Fixed with this code. Let me know if that's efficient writing.

#6 HotKeyIt

HotKeyIt
  • Fellows
  • 6132 posts

Posted 13 August 2012 - 10:40 AM

HotKeyIt: Why return 1 there?

Because you return false = 0 otherwise.