Rildoy

Ayuda!. Quiero unir dos secuencias de codigo sin compilar

9 posts in this topic

#1 ·  Posted

I made two code sequences separately and then put them together, but I get a variable declaration error, please support it with my project.

"D:\Techint\Programacion\Final_1303.au3" (137) : ==> Variable used without being declared.:
For $i = 0 To UBound($aPCAlias) - 1
For $i = 0 To UBound(^ ERROR

I made two code sequences separately and then put them together, but I get a variable declaration error, please support it with my project.

I send my code

Share this post


Link to post
Share on other sites



#2 ·  Posted

Just now, Rildoy said:

I made two code sequences separately and then put them together, but I get a variable declaration error, please support it with my project.

"D:\Techint\Programacion\Final_1303.au3" (137) : ==> Variable used without being declared.:
For $i = 0 To UBound($aPCAlias) - 1
For $i = 0 To UBound(^ ERROR

I made two code sequences separately and then put them together, but I get a variable declaration error, please support it with my project.

I send my code

#include <file.au3>
#include <array.au3>

#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>


#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Datos de Equipos", 279, 261, -1, -1)
$Button1 = GUICtrlCreateButton("Obtener Datos Locales", 16, 16, 249, 49)
$Admin = GUICtrlCreateInput(".\TEIAdmin", 18, 96, 249, 21)
$Label1 = GUICtrlCreateLabel("Ingresar datos de equipo Remoto", 24, 72, 192, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetCursor (-1, 2)
$Password = GUICtrlCreateInput("Password", 18, 128, 249, 21)
$Button2 = GUICtrlCreateButton("Obtener datos de Equipo Remioto", 16, 192, 249, 49)
$Host = GUICtrlCreateInput("Ingresar Host", 18, 160, 249, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            _WritePCInfo()

    EndSwitch
WEnd

#Region Datos
Local $fp_PCInfo = @ScriptDir & "\PCInfo.txt"
Local $strPCInfoFormat = "csv"


If FileExists($fp_PCInfo) Then
FileDelete($fp_PCInfo)
EndIf

Local $strNicConfig = "wmic /Node:$Host /User:$Admin  /Password:$Password nicconfig list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strOS    = "wmic /Node:$Host /User:$Admin  /Password:$Password OS list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strBOIS    = "wmic /Node:$Host /User:$Admin /Password:$Password bios list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strMemorychip    = "wmic /Node:$Host /User:$Admin /Password:$Password memorychip get manufacturer, PartNumber,SerialNumber,Capacity,DeviceLocator,MemoryType,Name,TotalWidth /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strCPU = "wmic /Node:$Host /User:$Admin /Password:$Password CPU list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strDiskdrive    = "wmic /Node:$Host /User:$Admin /Password:$Password diskdrive list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strSoundDev = "wmic /Node:$Host /User:$Admin /Password:$Password SoundDev list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strBaseboard    = "wmic /Node:$Host /User:$Admin /Password:$Password baseboard list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo

Local $aPCAlias[8][2]
$aPCAlias[0][0] = "OS"
$aPCAlias[0][1] = $strOS
$aPCAlias[1][0] = "BIOS"
$aPCAlias[1][1] = $strBOIS
$aPCAlias[2][0] = "Baseboard"
$aPCAlias[2][1] = $strBaseboard
$aPCAlias[3][0] = "CPU"
$aPCAlias[3][1] = $strCPU
$aPCAlias[4][0] = "Memory"
$aPCAlias[4][1] = $strMemorychip
$aPCAlias[5][0] = "Diskdrive"
$aPCAlias[5][1] = $strDiskdrive
$aPCAlias[6][0] = "Sound"
$aPCAlias[6][1] = $strSoundDev
$aPCAlias[7][0] = "Net"
$aPCAlias[7][1] = $strNicConfig

_WritePCInfo()
Local $aArray = FileReadToArray($fp_PCInfo)
Local $iRowIndex = 1

If UBound($aArray) <= 8 Then
MsgBox(0, "", "Can not collect PC information.")
Exit
EndIf

#Region ### START Koda GUI section ### Form=
$formPC = GUICreate("Información de Equipo", 1000, 437, 192, 124)
$tabType = GUICtrlCreateTab(10, 10, 982, 420)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

Local $lvHandle[UBound($aPCAlias)]
Local $strCurrentString, $aTemp
For $i = 0 To UBound($aPCAlias) - 1
GUICtrlCreateTabItem($aPCAlias[$i][0])

$strCurrentString = $aArray[$iRowIndex]
$lvHandle[$i] = GUICtrlCreateListView(StringReplace($strCurrentString, ",", "|"), 16, 35, 970, 390, bitor($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetBkColor(0x00E0FFFF)
$iRowIndex += 1

While $aArray[$iRowIndex] <> ""
$strCurrentString = $aArray[$iRowIndex]
If $aPCAlias[$i][0] == "Memory" Then
$aTemp = StringSplit($strCurrentString, ",", 2)
$aTemp[1] = _SwitchToMb($aTemp[1])
$strCurrentString = _ArrayToString($aTemp, ",")
EndIf

If $aPCAlias[$i][0] == "Diskdrive" Then
$aTemp = StringSplit($strCurrentString, ",", 2)
$aTemp[5] = _SwitchToMb($aTemp[5])
$strCurrentString = _ArrayToString($aTemp, ",")
EndIf

GUICtrlCreateListViewItem(StringReplace($strCurrentString, ",", "|"), $lvHandle[$i])
$iRowIndex += 1
If $iRowIndex = UBound($aArray) Then ExitLoop
WEnd

$iRowIndex += 1    ;jump the empty row
Next

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

Func _SwitchToMb($strNumber)
Return String(int(Number($strNumber) / (1024 * 1024))) & " Mb"
EndFunc

Func _WritePCInfo()
For $i = 0 To UBound($aPCAlias) - 1
;ConsoleWrite($aPCAlias[$i][1] & @CRLF)
RunWait(@ComSpec & " /c " & $aPCAlias[$i][1], @ScriptDir, @SW_HIDE)
_AppendLineToFile($fp_PCInfo, @CRLF)
Next
EndFunc

Func _AppendLineToFile($strFilepath, $strContent)
Local $hFileOpen = FileOpen($strFilepath, $FO_APPEND)
If $hFileOpen = -1 Then
MsgBox(0, "", "An error occurred when reading the file.")
Return False
EndIf

; Write data to the file using the handle returned by FileOpen.
FileWriteLine($hFileOpen, $strContent)

; Close the handle returned by FileOpen.
FileClose($hFileOpen)
EndFunc
#EndRegion Datos ###Equipo remoto###

Share this post


Link to post
Share on other sites

#3 ·  Posted

Nothing in your code that's placed after the While...Wend loop will ever get executed. So, none of the variables you have after it will get declared. You need to move that code elsewhere, either in a function or above the While loop.

Also, if you move it to a function, do NOT use local for the declaration. It's a bad idea to use Local in a global scope because it's misleading to the casual coder. Local variables in a global scope are Global variables.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted

you have declared $aPCAlias as Local, then how can read anything your function _WritePCInfo() ?

Share this post


Link to post
Share on other sites

#5 ·  Posted

BTW: When posting code please use AutoIt code tags in the editor (button "<>"). Makes your script much easier to read :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Gracias pos sus respuestas. Pero he tratado de cambiar de orden el codigo y cambiar las variables a Local, pero me aparecen mas errores que antes. mi verdadero problema es que tengo 2 codigos distintos el, uno es el archivo "Box With Buttons" y el otro es "Info_PC. por favor como podria hacer para que el un boton delcodigo "Box With Buttons" llame al codigo "Info_PC".

Desde ya muchas gracias, espero me comprendan ya que soy nuevo en AutoIT.

 

Box with Buttons.au3

Info_PC.au3

Share this post


Link to post
Share on other sites

#7 ·  Posted

Thank you for your answers. But I tried to change the code and change the variables to Local, but I get more errors than before. My real problem is that I have 2 different codes, one is the file "Box With Buttons" and the other one is "Info_PC. Please, how could I do it so that the one button of the code" Box With Buttons "calls the code" Info_PC".

From now on thank you very much, I hope you understand me since I am new to AutoIT.

Info_PC.au3

Box with Buttons.au3

Share this post


Link to post
Share on other sites

#8 ·  Posted

Hola. Y la información debería mostrarse en la ventana igual que el Código de Info PC.au3?

 

Saludos

 

PD: Este es un foro en ingles. Así que creo que deberías escribir en ingles. no al Español  :lol:


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

The information should be displayed in the "Info_PC" window. I want to join those two codes, that the code "Box With Buttons" call "Info_PC" and the information is displayed in the same window of "Info_PC" that is the one that collects the information.

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