首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Regexmach,结果存储gui editbox

Regexmach,结果存储gui editbox
EN

Stack Overflow用户
提问于 2019-05-09 02:07:04
回答 1查看 64关注 0票数 0

我有一个文本,在这个文本中的数据是变化的,我想收集必要的数据并显示在一个gui文本框中。第一个脚本是gui,第二个脚本可以从文本中提取数据。我希望只有这些值被加载到这些编辑框中。

例如:

UserInput1托尼

UserInput2 Stark

UserInput3 34234u4

ect...

第一

代码语言:javascript
复制
Gui, Add, Edit, x22 y39 w190 h20 vUserInput1 readonly,  
Gui, Add, Edit, x22 y79 w190 h20 vUserInput2 readonly,
Gui, Add, Edit, x22 y119 w190 h20 vUserInput3 readonly,
Gui, Add, Edit, x22 y159 w190 h20 vUserInput4 readonly,
Gui, Add, Edit, x22 y199 w190 h20 vUserInput5 readonly,
Gui, Add, Edit, x22 y239 w190 h20 vUserInput6 readonly,
Gui, Add, Edit, x22 y279 w190 h20 vUserInput7 readonly,
Gui, Add, Edit, x22 y319 w190 h20 vUserInput8 readonly,
Gui, Add, Edit, x22 y359 w190 h20 vUserInput9 readonly,
; Generated using SmartGUI Creator 4.0
Gui, Show, x127 y87 h508 w242, New GUI Window
Return

GuiClose:
ExitApp

第二声

代码语言:javascript
复制
str=
(
|-----------------------------------+-+-----------------------------------|
| Title | |Mr. |
|-----------------------------------+-+-----------------------------------|
| First Name * | |TONY |
|-----------------------------------+-+-----------------------------------|
| Last Name * | |STARK |
|-----------------------------------+-+-----------------------------------|
| Please select the reference | |Rental Agreement Number |
| number type you can provide * | | |
|-----------------------------------+-+-----------------------------------|
| Providing Number / ID * | |1111111 |
|-----------------------------------+-+-----------------------------------|
| Reservierungsnummer | |34234u4 |
|-----------------------------------+-+-----------------------------------|
| Country of Rental * | |usa |
|-----------------------------------+-+-----------------------------------|
| Rental Station[<BR>](address) | |Airport |
|-----------------------------------+-+-----------------------------------|
| Pick-Up Date | |15/04/2019 |
|-----------------------------------+-+-----------------------------------|
| Return Date | |18/04/2019 |
|-----------------------------------+-+-----------------------------------|
| E-Mail Address * | |tony.stark@pwaero.utc.com |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
| | | |
|-----------------------------------+-+-----------------------------------|
)
Loop, Parse, str, `n, `r
{
    If (RegExMatch(A_LoopField,"^\|------|^\| \||Title|Agreement|type") > 0 )
        continue
    m := StrSplit(A_LoopField, "|")

    gui, add, text, xm,% m[4]
}

return

GuiEscape:
GuiClose:
Esc::
  ExitApp
return
EN

回答 1

Stack Overflow用户

发布于 2019-05-20 22:42:49

我假设您想要做的是从第二个脚本中的字符串加载只读Edit控件的字段。

为了更改编辑控件的内容,假设您是从创建图形用户界面的同一脚本执行此操作,您可以使用GuiControl命令,以及允许您设置已经创建的控件的文本的子命令Text,而不是向图形用户界面添加新的文本控件。

此命令的语法为:

代码语言:javascript
复制
GuiControl, Text, ControlID[, Value]

其中,ControlID是与手边的控件(UserInput1UserInput2等)关联的变量(或者它的类名和实例号(在本例中是Edit1Edit2和successively),或者控件的唯一标识符,即它的HWND)。

例如,您可以将您的循环替换为以下循环:

代码语言:javascript
复制
count = 1
Loop, Parse, str, `r`n,
{
    If (RegExMatch(A_LoopField,"^\|------|^\| \||Title|Agreement|type") > 0 )
        continue
    m := StrSplit(A_LoopField, "|")

    GuiControl, Text, UserInput%count%, % m[4]
    count += 1
}

这样就能达到目的了。请注意,我每次都使用count变量来引用正确的Edit控件。

你不必担心编辑控件是ReadOnly,因为这个设置只允许用户修改它的内容,而不是你的脚本。

我还通过`r`n更改了循环的分隔符,这是解析循环的适当行分隔符,但这不会影响您的脚本。

然而,前面的方法假设与图形用户界面的控件相关的变量(UserInput1UserInput2,...)在第二个脚本中也存在,如果它们都包含在同一主脚本中,使用#include指令或手动将它们粘贴到同一文件中,则不会发生not

如果您的脚本由于某种原因(可能不是)需要是并行执行的独立进程,您仍然可以使用命令ControlSetText来设置第二个脚本中的控件文本,该命令的语法为:

代码语言:javascript
复制
ControlSetText[, Control, NewText, WinTitle, WinText, ExcludeTitle, ExcludeText]

在本例中,您可以在第N个编辑控件的Control参数中指定“EditN”,并为WinTitle参数指定“New GUI Window ahk_class AutoHotkeyGUI”(并保留其他参数为空),这将与您的图形用户界面的窗口和控件相匹配(除非存在多个具有相同标题的AutoHotkeyGUI,或者在图形用户界面中的第一个编辑控件之前存在多个编辑控件)。[More about the WinTitle parameter]。

使用此命令,您的循环可以重写为:

代码语言:javascript
复制
count = 1
Loop, Parse, str, `r`n
{
    If (RegExMatch(A_LoopField,"^\|------|^\| \||Title|Agreement|type") > 0 )
        continue
    m := StrSplit(A_LoopField, "|")

    ControlSetText, Edit%count%, % m[4], New GUI Window ahk_class AutoHotkeyGUI
    count += 1
}

当然,您可以将“New GUI Window”替换为您可能使用的任何标题。

另一方面,我强烈建议您考虑一种不同的策略来存储图形用户界面的数据,而不是使用复杂的标记语法和自定义的(但有效的) RegEx。

有许多不同的方法可以将脚本的数据存储在单独的文件中,但一个非常简单的方法是使用Ini File,它能够存储按段组织的信息的键-值对,AutoHotKey为此提供了内置命令IniReadIniWriteIniDelete

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56046703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档