ur

To count number of arguments.

7 posts in this topic

I need to write a code in which I am reading a text file which is of .vbs format and in that a line contains function signature like below

Function CreateEnvironmentVariable($sType, $sName, $sValue, $bOverwrite)

If the string is in above format, then I need to check number of arguments in it.

For in above case it should return 4.

Can anyone help me on this.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@ur what have you tried on your own? Look at FileReadToArray in the help file to read the file in, and parse through it line by line. You can then use StringInStr to parse each line, something like this:

If StringInStr($aArray[$i], "CreateEnvironmentVariable") Then
   ;Count number of params
EndIf

 

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Got the code...

#include <StringConstants.au3>

$s = "Function CreateEnvironmentVariable($sType, $sName, $sValue, $bOverwrite)"
MsgBox(0,"",CountArgs($s))
Func CountArgs($strFunctionName)
    ;to differentiate between small brackets in strings
    $strFunctionName = StringStripWS($strFunctionName, $STR_STRIPLEADING + $STR_STRIPTRAILING)
    $strFunctionName = StringReplace ( $strFunctionName, "(", "~OSBS~" , 1 )
    $strFunctionName = StringReplace ( $strFunctionName, ")", "~OSBE~" , -1 )
    $strFunctionName = StringReplace ( $strFunctionName, "(", "~DSBS~" )
    $strFunctionName = StringReplace ( $strFunctionName, ")", "~DSBE~" )
    $strFunctionName = StringReplace ( $strFunctionName, "~OSBE~" ,")", -1 )
    $strFunctionName = StringReplace ( $strFunctionName, "~OSBS~","(", 1 )


   Local $arrStrProcedureArguments = StringSplit ( $strFunctionName, "," )
    ;_ArrayDisplay($arrStrProcedureArguments)
    Return $arrStrProcedureArguments[0]
EndFunc

 

Share this post


Link to post
Share on other sites

That would have been helpful in post 1 :) So what, exactly, is not working for you?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

That would have been helpful in post 1 :) So what, exactly, is not working for you?

Yeah it is working fine now, I got the solution after posting the question.So I posted my code here.

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

  • Similar Content

    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • Miliardsto
      By Miliardsto
      Im creating a tab
      Global $Tab1 = GUICtrlCreateTab(30, 30, 600, 420, $TCS_BUTTONS, -1) And what we see in the function reference:
      https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTab.htm
      GUICtrlCreateTab ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] ) ok in 5 arg I got $TCS_BUTTONS
      But How can I use multiple args like this below
      Global $Tab1 = GUICtrlCreateTab(30, 30, 600, 420, [$TCS_BUTTONS, $TCS_MULTILINE], -1)  
    • mati
      By mati
      Hi,
      I wonder if
      AutoIt3Wrapper_run_debug_mode = Y can include run information about functions which are called within the main code. So far I noticed in the console that the function itself is called but no specific run information from  inside the function is provided. Is there a chance to show the entire debug log including functions in the console?
      I furthermore noticed a stop of information when a loop is entered. What could be the reason for that?
       
      Thanks for help.
    • TrashBoat
      By TrashBoat
      Is this possible:
      Executing a function from an include, but taking the function name from a gui input and then executing that function using the include:
      #include <Something.au3> ;input reads "Tree" $functionName = GuiCtrlRead($input1) $functionName(1) And the include is gonna have
      Func Tree($x) If $x = 1 Then $this = "text" MsgBox(0,$this,"whatever") EndFunc is it possible?
    • hcI
      By hcI
      Hello, i'm making a little script that lets users enter a question and if the script can't answer to, it ask what would be the answer (a bit like siri on IPhones). And I try to display the "supposed array" I still have an error.. I searched on Google and got nothing looked in the help file too.. I'm here to know if someone have a solution to my error please.
      Here is where $a and $b should become arrays :
      Dim $dossier = @AppDataDir & "\Siri2" Dim $chemin = $dossier & "\data.ini" Global $a = _InfoRead($chemin, 0) Global $b = _InfoRead($chemin, 1) with this function :
      Func _InfoRead($path, $mode = 0) If DirGetSize($dossier) = -1 Then Return SetError(-4) If Not FileExists($chemin) Then Return SetError(-5) Local $readed = IniReadSection($path, "data") If @error Then Return SetError(-3) $size = $readed[0][0] Local $return[$size] For $i = 1 To $size Step 1 $return[$i - 1] = $readed[$i][$mode] Next Return $return EndFunc and the thing that i don't understand is that, after _InfoRead return affected to $a, I can't use _ArrayDisplay because of  error 1 "$aArray is not an array" (and same fpr the variable $b)..
      Can please someone help me to understand why is it doing this ?

      -hcI