yanjerry9133 发表于 2011-7-22 20:16:59

如何将input中数据存入数组中

请问如何将input1,input2,input3....中的数据存入一个数组中,并用msgbox()显示出来。。。我先谢谢大家了。。。

sxd 发表于 2011-7-23 03:01:21



#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 261, 121, 192, 124)
$Input1 = GUICtrlCreateInput("", 8, 8, 121, 21)
$Input2 = GUICtrlCreateInput("", 8, 40, 121, 21)
$Input3 = GUICtrlCreateInput("", 8, 72, 121, 21)
$Button1 = GUICtrlCreateButton("保存", 152, 16, 75, 25)
$Button2 = GUICtrlCreateButton("显示", 152, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Dim $aInputs
$aInputs = 3
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $aInputs = GUICtrlRead($Input1)
                        $aInputs = GUICtrlRead($Input2)
                        $aInputs = GUICtrlRead($Input3)
                        MsgBox(0,0,"保存完成")
                Case $Button2
                        For $i = 1 To 3
                                MsgBox(0,0,"Input" & $i & "的内容为:" & $aInputs[$i])
                        Next
                       
        EndSwitch
WEnd

yanjerry9133 发表于 2011-7-25 13:31:38

非常感谢。。。

yanjerry9133 发表于 2011-7-25 14:15:53

回复 2# sxd
Case $Button1
                        $aInputs = GUICtrlRead($Input1)
                        $aInputs = GUICtrlRead($Input2)
                        $aInputs = GUICtrlRead($Input3)
                        MsgBox(0,0,"保存完成")
如果有100个inputbox,那用循环怎么写上面这段。

3mile 发表于 2011-7-25 15:41:17

回复 4# yanjerry9133
怎么就不肯动点脑子呢?
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 261, 800, 192, 124)
Local $Input, $aInputs, $str
For $i = 0 To UBound($Input) - 1
        $Input[$i] = GUICtrlCreateInput("", 8, 8 + $i * 32, 121, 21)
Next
$Button1 = GUICtrlCreateButton("保存", 152, 16, 75, 25)
$Button2 = GUICtrlCreateButton("显示", 152, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        For $i = 0 To UBound($Input) - 1
                                $aInputs = GUICtrlRead($Input[$i])
                        Next
                        MsgBox(0, 0, "保存完成")
                Case $Button2
                        $str = ""
                        For $i = 0 To UBound($Input) - 1
                                $str &= "Input" & $i + 1 & "的内容为:" & $aInputs[$i] & @CRLF
                        Next
                        MsgBox(0, 0, $str)
        EndSwitch
WEnd

sxd 发表于 2011-7-28 00:01:58

笔误
$aInputs[$i] = GUICtrlRead($Input[$i])

yanjerry9133 发表于 2011-8-2 15:01:27

回复 5# 3mile
我动脑子了,只是想看看能不能这样写input[$i],哈哈,那我就会了。。。
页: [1]
查看完整版本: 如何将input中数据存入数组中