Показать полную графическую версию : [решено] Скрипт создания файла данных через диологовое окно. как?
Помогите создать скрипт который бы создовал файл с расширением exp (обычный текстовый файл только с переименованным расширением). При этом нужно чтобы в файл вносились данные по определенному алгоритму.
Пример файла который нужно получить:
[mm]p9=128
[mm]p10=133
[mm]p11=137
[mm]p12=25
[mm]p13=65
[mm]p14=60
[mm]p15=8
[mm]p16=89
[mm]p17=17
и так далее...
При запуске скрипта должно выскачить окно в котором можно ввести данные. Пример окна:
Диаметр окружности впадин зубьев, df 128
Делительный диаметр, d 133
Диаметр окружности вершин зубьев, da 137
Ширина, b 25
Диаметр ступицы, dst 65
Длина ступицы, Lst 60
Толщина венца, hv 8
Диаметр расположения отверстий, dro 89
Диаметр отверстий, do 17
То что текстом - это пояснения, а для цифр должно быть поле для их ввода. При этом каждой фразе пояснения должно автоматически подставлятся [mm]p17=. Но не по порядку как в примере. Фраза в скобках и цифра после p может быть любая, заранее мною определенная для каждой фразы пояснения. После того как все данные введены нажимаем OK и должен получится нужный файл.
#include <GUIConstantsEx.au3>
$hWrite = FileOpen(@ScriptDir & '\file.ext', 2)
$hGUI = GUICreate('I''m a crasy dentist', 300, 300)
$hButton = GUICtrlCreateButton('Create file', 10, 260, 70, 30)
Local $hLabel[9][2], $sLabel[9], $hInput[9]
$sLabel[0] = 'Диаметр окружности впадин зубьев, df'
$sLabel[1] = 'Делительный диаметр, d'
$sLabel[2] = 'Диаметр окружности вершин зубьев, da'
$sLabel[3] = 'Ширина, b'
$sLabel[4] = 'Диаметр ступицы, dst'
$sLabel[5] = 'Длина ступицы, Lst'
$sLabel[6] = 'Толщина венца, hv'
$sLabel[7] = 'Диаметр расположения отверстий, dro'
$sLabel[8] = 'Диаметр отверстий, do'
$hLabel[0][1] = '[mm]p9='
$hLabel[1][1] = '[mm]p10='
$hLabel[2][1] = '[mm]p11='
$hLabel[3][1] = '[mm]p12='
$hLabel[4][1] = '[mm]p13='
$hLabel[5][1] = '[mm]p14='
$hLabel[6][1] = '[mm]p15='
$hLabel[7][1] = '[mm]p16='
$hLabel[8][1] = '[mm]p17='
For $i = 0 to 8
$hLabel[$i][0] = GUICtrlCreateLabel($sLabel[$i], 10, 10 + $i * 28, 180, 15)
$hInput[$i] = GUICtrlCreateInput($i, 230, 10 + $i * 28, 50, 15)
Next
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
GUIDelete($hGUI)
ExitLoop
Case $hButton
For $i = 0 to 8
FileWriteLine($hWrite, $hLabel[$i][1] & GUICtrlRead($hInput[$i]))
Next
FileClose($hWrite)
EndSwitch
WEnd
kaster, а можно чтобы скрипт отслеживал введенные значения по полученному файлу?
в чем проявляется слежение? и какой вид имеет полученный файл?
какой вид имеет полученный файл? »
полученный файл имеет вид как нужно. Все работает ок. Объясню подробнее. вот допустим я ввел данные. Когда в следующий раз запущу скрипт то в ячейках будут цифры по умолчанию. А хотелось бы чтоб цифры там были из последнего сеанса запуска, тобишь из файла file.ext
и зашитые по умолчанию цифры 1 2 3 4 5 ... как поменять на нужные не понял я что то
а. понял. последние введенные данные.
а выходной файл может иметь вид следующий?
[settings]
[mm]p9=128
[mm]p10=133
[mm]p11=137
[mm]p12=25
[mm]p13=65
[mm]p14=60
[mm]p15=8
[mm]p16=89
[mm]p17=17
ну или любое другое значение вместо [settings]? просто в таком случае это получится ini файл для парсинга которого есть встроенные средства. в противном случае есть два варианта
1. длинный, и не совсем понятный для тебя судя по вопросам, код
2. создание вспомогательного файла, который будет практически дублировать file.ext но с заголовком [settings]
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('I''m a crasy dentist', 300, 300)
$hButton = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Create file', 10, 260, 70, 30)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hLabel[9][2], $sLabel[9], $hInput[9]
$sLabel[0] = 'Диаметр окружности впадин зубьев, df'
$sLabel[1] = 'Делительный диаметр, d'
$sLabel[2] = 'Диаметр окружности вершин зубьев, da'
$sLabel[3] = 'Ширина, b'
$sLabel[4] = 'Диаметр ступицы, dst'
$sLabel[5] = 'Длина ступицы, Lst'
$sLabel[6] = 'Толщина венца, hv'
$sLabel[7] = 'Диаметр расположения отверстий, dro'
$sLabel[8] = 'Диаметр отверстий, do'
$hLabel[0][1] = '[mm]p9='
$hLabel[1][1] = '[mm]p10='
$hLabel[2][1] = '[mm]p11='
$hLabel[3][1] = '[mm]p12='
$hLabel[4][1] = '[mm]p13='
$hLabel[5][1] = '[mm]p14='
$hLabel[6][1] = '[mm]p15='
$hLabel[7][1] = '[mm]p16='
$hLabel[8][1] = '[mm]p17='
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 8
$sInput_Val = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)(FileReadLine (http://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm)(@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & '\file.ext', $i + 1), "^.*=(.*)$", "\1")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sInput_Val = "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sInput_Val = $i
$hLabel[$i][0] = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)($sLabel[$i], 10, 10 + $i * 28, 180, 15)
$hInput[$i] = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)($sInput_Val, 230, 10 + $i * 28, 50, 17, $ES_NUMBER)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$Msg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $Msg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
GUIDelete (http://www.autoitscript.com/autoit3/docs/functions/GUIDelete.htm)($hGUI)
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hButton
$hWrite = FileOpen (http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm)(@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & '\file.ext', 2)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 8
FileWriteLine (http://www.autoitscript.com/autoit3/docs/functions/FileWriteLine.htm)($hWrite, $hLabel[$i][1] & GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($hInput[$i]))
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
FileClose (http://www.autoitscript.com/autoit3/docs/functions/FileClose.htm)($hWrite)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
а выходной файл может иметь вид следующий? »
не, не может. прога ругается на данную строку, или любую другую. Ошибка вроде не критическая, но рисковать мне нельзя (запороть проект 3D не хочу).
длинный, и не совсем понятный для тебя судя по вопросам, код »
если есть лишнее время то можете предложить, но наверное лучше
создание вспомогательного файла, который будет практически дублировать file.ext но с заголовком [settings] »
и пусть скрипт делает его сразу же скрытым чтобы на глазах не моячил
kaster, Вас опередили. Creat0R, все работает как нельзя лучше. Если мне нужно увеличить количество параметров то я меняю:
$sLabel[9] = 'Диаметр отверстий, do'
.....
$hLabel[9][1] = '[mm]p17='
....
For $i = 0 To 9
For $i = 0 To 9
Local $hLabel[10][2], $sLabel[10], $hInput[10]
Верно?
Верно? »
Да. Но я бы для удобства сделал так:
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('I''m a crasy dentist', 300, 350)
$hButton = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Create file', 10, 310, 70, 30)
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $aLabels, $aInput_Vals, $aiInputs, $iCount
$aLabels &= 'Диаметр окружности впадин зубьев, df|'
$aLabels &= 'Делительный диаметр, d|'
$aLabels &= 'Диаметр окружности вершин зубьев, da|'
$aLabels &= 'Ширина, b|'
$aLabels &= 'Диаметр ступицы, dst|'
$aLabels &= 'Длина ступицы, Lst|'
$aLabels &= 'Толщина венца, hv|'
$aLabels &= 'Диаметр расположения отверстий, dro|'
$aLabels &= 'Диаметр отверстий, do|'
$aInput_Vals &= '[mm]p9=|'
$aInput_Vals &= '[mm]p10=|'
$aInput_Vals &= '[mm]p11=|'
$aInput_Vals &= '[mm]p12=|'
$aInput_Vals &= '[mm]p13=|'
$aInput_Vals &= '[mm]p14=|'
$aInput_Vals &= '[mm]p15=|'
$aInput_Vals &= '[mm]p16=|'
$aInput_Vals &= '[mm]p17=|'
$aLabels = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($aLabels, '\|$', '')
$aLabels = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($aLabels, '|')
$aInput_Vals = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($aInput_Vals, '\|$', '')
$aInput_Vals = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($aInput_Vals, '|')
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $iCount = $aInput_Vals[0]
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $aiInputs[$iCount+1]
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $iCount
$sVal = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)(FileReadLine (http://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm)(@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & '\file.ext', $i), "^.*=(.*)$", "\1")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sVal = "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sVal = $i
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)($aLabels[$i], 10, 10 + ($i-1) * 28, 180, 15)
$aiInputs[$i] = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)($sVal, 230, 10 + ($i-1) * 28, 50, 17, $ES_NUMBER)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$Msg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $Msg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
GUIDelete (http://www.autoitscript.com/autoit3/docs/functions/GUIDelete.htm)($hGUI)
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hButton
$hWrite = FileOpen (http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm)(@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & '\file.ext', 2)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $iCount
FileWriteLine (http://www.autoitscript.com/autoit3/docs/functions/FileWriteLine.htm)($hWrite, $aInput_Vals[$i] & GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($aiInputs[$i]))
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
FileClose (http://www.autoitscript.com/autoit3/docs/functions/FileClose.htm)($hWrite)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Добавлять так:
$aLabels &= 'Диаметр отверстий, do|'
...
$aInput_Vals &= '[mm]p17=|'
...
Верно? »
да. надо переобъявить массивы и изменить верхний предел циклов
Creat0R, ну да, так удобнее :) Спасибо всем за помощь! Сильно облегчили мне жизнь в проектировании.
Creat0R, ща глянул а файл что мне нужно получить имеет большое количество параметров. В связи с этим вопрос как изменить интервал между строками и можно ли как то окно сделать в два или даже три столбца?
Creat0R, как менять разные расстояния понял а как сделать в два (три) столбца нет. Помогите пожалуйста
В связи с этим вопрос как изменить интервал между строками и можно ли как то окно сделать в два или даже три столбца? »
Как раз для таких случаев есть _GUIScrollBars*:
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIScrollBars.au3>
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('I''m a crasy dentist', 300, 350)
$hButton = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Create file', 5, 317, 70, 25)
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $aLabels, $aInput_Vals, $aiInputs, $iCount, $iScroll_Max
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $sFile = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & '\file.ext'
$aLabels &= 'Диаметр окружности впадин зубьев, df|'
$aLabels &= 'Делительный диаметр, d|'
$aLabels &= 'Диаметр окружности вершин зубьев, da|'
$aLabels &= 'Ширина, b|'
$aLabels &= 'Диаметр ступицы, dst|'
$aLabels &= 'Длина ступицы, Lst|'
$aLabels &= 'Толщина венца, hv|'
$aLabels &= 'Диаметр расположения отверстий, dro|'
$aLabels &= 'Диаметр отверстий, do|'
$aInput_Vals &= '[mm]p9=|'
$aInput_Vals &= '[mm]p10=|'
$aInput_Vals &= '[mm]p11=|'
$aInput_Vals &= '[mm]p12=|'
$aInput_Vals &= '[mm]p13=|'
$aInput_Vals &= '[mm]p14=|'
$aInput_Vals &= '[mm]p15=|'
$aInput_Vals &= '[mm]p16=|'
$aInput_Vals &= '[mm]p17=|'
$aLabels = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($aLabels, '\|$', '')
$aLabels = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($aLabels, '|')
$aInput_Vals = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($aInput_Vals, '\|$', '')
$aInput_Vals = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($aInput_Vals, '|')
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $iCount = $aInput_Vals[0]
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $aiInputs[$iCount+1]
$hData_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Data GUI", 290, 300, 0, 0, $WS_CHILD, $WS_EX_CLIENTEDGE+$WS_EX_DLGMODALFRAME, $hGUI)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $iCount
$sVal = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)(FileReadLine (http://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm)($sFile, $i), "^.*=(.*)$", "\1")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sVal = "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sVal = $i
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)($aLabels[$i], 10, 10 + ($i-1) * 28, 180, 15)
$aiInputs[$i] = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)($sVal, 220, 10 + ($i-1) * 28, 50, 17, $ES_NUMBER)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
GUIRegisterMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm)($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($hData_GUI)
_GUIScrollBars_SetScrollInfoMax($hData_GUI, $SB_HORZ, 0)
_GUIScrollBars_SetScrollInfoMax($hData_GUI, $SB_VERT, $iCount * 2)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_SHOW), $hData_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_SHOW), $hGUI)
GUISwitch (http://www.autoitscript.com/autoit3/docs/functions/GUISwitch.htm)($hGUI)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$Msg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $Msg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
GUIDelete (http://www.autoitscript.com/autoit3/docs/functions/GUIDelete.htm)($hGUI)
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hButton
$hWrite = FileOpen (http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm)($sFile, 2)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $iCount
FileWriteLine (http://www.autoitscript.com/autoit3/docs/functions/FileWriteLine.htm)($hWrite, $aInput_Vals[$i] & GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($aiInputs[$i]))
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
FileClose (http://www.autoitscript.com/autoit3/docs/functions/FileClose.htm)($hWrite)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nScrollCode = BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)($wParam, 0x0000FFFF)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $index = -1, $yChar, $yPos
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $Min, $Max, $Page, $Pos, $TrackPos
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $x = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) UBound (http://www.autoitscript.com/autoit3/docs/functions/UBound.htm)($aSB_WindowInfo) - 1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aSB_WindowInfo[$x][0] = $hWnd Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $index = -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) 0
; Get all the vertial scroll bar information
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tSCROLLINFO, "nMin")
$Max = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tSCROLLINFO, "nMax")
$Page = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$yPos = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tSCROLLINFO, "nTrackPos")
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nScrollCode
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_TOP ; user clicked the HOME keyboard key
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $Min)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_BOTTOM ; user clicked the END keyboard key
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $Max)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_LINEUP ; user clicked the top arrow
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $Pos - 1)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_LINEDOWN ; user clicked the bottom arrow
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $Pos + 1)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $Pos - $Page)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $Pos + $Page)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
;~ // Set the position and then retrieve it. Due to adjustments
;~ // by Windows it may not be the same as the value set.
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tSCROLLINFO, "nPos")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) ($Pos <> $yPos) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $GUI_RUNDEFMSG
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>WM_VSCROLL
Вроде все отлично. если возникнут еще вопросы спрошу.
PS Не обязательно но для удобства: Как сделать чтобы данное окно было поверх всех окон?
Можно ли как то задать определенные координаты появления окна? (как пример - верхний левый угол)
Creat0R, пока спал пришла мысль. может ли автоит вытянуть параметры что я ввожу руками в Вами предложенный скрипт из файла EXCEL. Суть такова: EXCEL файл считает мне кучу параметров и потом сводит их в один столбец. В соседнем столбце могут быть:
[mm]p9=
[mm]p10=
[mm]p11=
[mm]p12=
[mm]p13=
[mm]p14=
[mm]p15=
[mm]p16=
[mm]p17=
то есть получится два столбца с параметрами и значениями. Может ли автоит скрипт залезть в EXCEL, вытянуть эти параметры и сделать файл с расширением exp?
HORRIBLE
22-12-2009, 14:22
Pozia, можно:
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIScrollBars.au3>
#include <Excel.au3>
$hGUI = GUICreate('I''m a crasy dentist', 300, 350)
$hButton = GUICtrlCreateButton('Create file', 5, 317, 70, 25)
$hButton_excel = GUICtrlCreateButton('Из EXCEL', 225, 317, 70, 25)
;----- Для EXCEL ------------------------------------------------
Global $sFileExcel = @ScriptDir & "\book.xls" ; имя файла
Global $num_row = 12 ; номер строки с которого начинаются нужные значения
Global $num_col = 8 ; номер столбца в котором находятся значения
;-----------------------------------------------------------------
Global $aLabels, $aInput_Vals, $aiInputs, $iCount, $iScroll_Max
Global $sFile = @ScriptDir & '\file.ext'
$aLabels &= 'Диаметр окружности впадин зубьев, df|'
$aLabels &= 'Делительный диаметр, d|'
$aLabels &= 'Диаметр окружности вершин зубьев, da|'
$aLabels &= 'Ширина, b|'
$aLabels &= 'Диаметр ступицы, dst|'
$aLabels &= 'Длина ступицы, Lst|'
$aLabels &= 'Толщина венца, hv|'
$aLabels &= 'Диаметр расположения отверстий, dro|'
$aLabels &= 'Диаметр отверстий, do|'
$aInput_Vals &= '[mm]p9=|'
$aInput_Vals &= '[mm]p10=|'
$aInput_Vals &= '[mm]p11=|'
$aInput_Vals &= '[mm]p12=|'
$aInput_Vals &= '[mm]p13=|'
$aInput_Vals &= '[mm]p14=|'
$aInput_Vals &= '[mm]p15=|'
$aInput_Vals &= '[mm]p16=|'
$aInput_Vals &= '[mm]p17=|'
$aLabels = StringRegExpReplace($aLabels, '\|$', '')
$aLabels = StringSplit($aLabels, '|')
$aInput_Vals = StringRegExpReplace($aInput_Vals, '\|$', '')
$aInput_Vals = StringSplit($aInput_Vals, '|')
Dim $iCount = $aInput_Vals[0]
Dim $aiInputs[$iCount+1]
$hData_GUI = GUICreate("Data GUI", 290, 300, 0, 0, $WS_CHILD, $WS_EX_CLIENTEDGE+$WS_EX_DLGMODALFRAME, $hGUI)
For $i = 1 To $iCount
$sVal = StringRegExpReplace(FileReadLine($sFile, $i), "^.*=(.*)$", "\1")
If $sVal = "" Then $sVal = $i
GUICtrlCreateLabel($aLabels[$i], 10, 10 + ($i-1) * 28, 180, 15)
$aiInputs[$i] = GUICtrlCreateInput($sVal, 220, 10 + ($i-1) * 28, 50, 17, $ES_NUMBER)
Next
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($hData_GUI)
_GUIScrollBars_SetScrollInfoMax($hData_GUI, $SB_HORZ, 0)
_GUIScrollBars_SetScrollInfoMax($hData_GUI, $SB_VERT, $iCount * 2)
GUISetState(@SW_SHOW, $hData_GUI)
GUISetState(@SW_SHOW, $hGUI)
GUISwitch($hGUI)
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
GUIDelete($hGUI)
ExitLoop
Case $hButton
$hWrite = FileOpen($sFile, 2)
For $i = 1 To $iCount
FileWriteLine($hWrite, $aInput_Vals[$i] & GUICtrlRead($aiInputs[$i]))
Next
FileClose($hWrite)
Case $hButton_excel
$oExcel = _ExcelBookOpen($sFileExcel)
If @error = 1 Then
MsgBox(0, "Error!", "Unable to Create the Excel Object")
ElseIf @error = 2 Then
MsgBox(0, "Error!", "File does not exist - Shame on you!")
Else
For $i = 1 to Ubound($aiInputs)-1
$sCellValue = _ExcelReadCell($oExcel, $i+($num_row-1), $num_col)
GUICtrlSetData($aiInputs[$i], $sCellValue)
Next
_ExcelBookClose($oExcel)
EndIf
EndSwitch
WEnd
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
; Get all the vertial scroll bar information
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
Case $SB_TOP ; user clicked the HOME keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM ; user clicked the END keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Max)
Case $SB_LINEUP ; user clicked the top arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINEDOWN ; user clicked the bottom arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
;~ // Set the position and then retrieve it. Due to adjustments
;~ // by Windows it may not be the same as the value set.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_VSCROLL
Я сделал файл book.xls нужные значения начинались со строки 12 и столбца 8 (почему такие числа, так просто)
HORRIBLE, у меня положение двух столбцов с параметрами и значениями находятся не вверху а ниже, где то на 50 строке. Как это учесть? И можно ли сделать без запуска экселя?
HORRIBLE
22-12-2009, 15:13
Pozia, это учитывается здесь:
$num_row = номер строки, в вашем примере видимо это будет число 50
$num_col = номер столбца, вытащил эти строки в начала кода....
И можно ли сделать без запуска экселя? Не могу ответить, открываемое окно можно скрыть просто. Для этого нужно: $oExcel = _ExcelBookOpen($sFileExcel) заменить на $oExcel = _ExcelBookOpen($sFileExcel,0)
И можно ли сделать без запуска экселя? »
нет. в любом случае нужна программа для открытия xls файла. либо Excel, либо oOO Calc, и т.д. если бы можно было читать оттуда данные без каких-либо программ, то не было бы смысла ставить Office. я думаю, это очевидно.
$num_row = номер строки, в вашем примере видимо это будет число 50
$num_col = номер столбца, вытащил эти строки в начала кода.... »
я сразу там и вставлял нужные цифры но не так понял пояснения.
Еще есть пожелание. Было бы хорошо, чтобы скрипт помимо самих значений еще и параметры типа:
[mm]p9=
[mm]p10=
[mm]p11=
[mm]p12=
[mm]p13=
[mm]p14=
[mm]p15=
[mm]p16=
[mm]p17=
вытягивал из экселя. То есть в экселе у меня столбец параметров и рядом столбец чисел. Серипт должен их оттуда вытянуть и в принципе диалог мне не нужен. Просто пусть выскочит окно с кнопкой "ОК" что файл создан. А в скрипте хотелось бы только задать начало и конец столбца параметров и столбца чисел. Кстати если страниц несколько в эксель файле то как скрипт знает с какой страницы ему открыть числа?
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC