多谢你的热心回复!在NiceLabel中的帮助文件是:Microsoft Windows Script Technologies ,我在该帮助文件中搜索关键字: passowrdchar,没有任何结果。。如果我在NiceLabel中使用Prompt1.passwordchar= "*" (Note:Prompt1是我创建的一个变量,是一个text) Error Code: Error ID: 150603 Error description: 'The syntax validation of the script failed.' Detailed information: 'Script error: 对象不支持此属性或方法: 'Prompt1.passwordchar' Line number: 1' Possible solution: '' Severity ID: 3 Severity name: 'Error' Available actions: OK Default action: OK Group ID: 17 Type ID: 2 Can disable dialog: NO
补充一下我上面说的:如果你在windows上创建一个vbs的脚本文件。你怎么隐藏输入的内容? inputbox("please enter your name") 如果我输入"1234".怎么显示为“*”?多谢~~
首先,我要狠狠的晕一下:你说的是VBS,我说的是VBA,不是一个东东啊~~~接着澄清一下:VBS是没有上面所说的TextBox,再者,VBS的Inputbox也没有Passwordchar属性(或参数),所以理论上VBS没有直接又便捷的方式来实现你的要求的。然后,根据你所说的Microsoft Windows Script Technologies猜测NiceLabel可能支持Wscript(也是微软的一个脚本语言)。以下代码你看看能不能用Sub ShowTheInputbox() strPw = GetPassword("Please enter your password:") MsgBox "Your password is: " & strPw End SubFunction Password( myPrompt ) Dim objPassword Set objPassword = CreateObject( "ScriptPW.Password" )
With objIE.Document.ParentWindow.Screen objIE.Left = (.AvailWidth - objIE.Width) \ 2 objIE.Top = (.Availheight - objIE.Height) \ 2 End With
' Insert the HTML code to prompt for a password objIE.Document.Body.InnerHTML = "<DIV ALIGN=""center""><P>" & myPrompt _ & "</P>" & vbCrLf _ & "<P><INPUT TYPE=""password"" SIZE=""20"" " _ & "ID=""Password""></P>" & vbCrLf _ & "<P><INPUT TYPE=""hidden"" ID=""OK"" " _ & "NAME=""OK"" VALUE=""0"">" _ & "<INPUT TYPE=""submit"" VALUE="" OK "" " _ & "OnClick=""VBScript:OK.Value=1""></P></DIV>"
objIE.Visible = True On Error Resume Next Do While objIE.Document.All.OK.Value = 0 If Err Then 'user clicked red X (or alt-F4) to close IE window IELogin = Array("", "") objIE.Quit Set objIE = Nothing Exit Function End If Loop On Error GoTo 0 GetPassword = objIE.Document.All.Password.Value objIE.Quit Set objIE = Nothing End Function'这句只是我拿来测试用的 Sub ShowTheInputbox() strPw = GetPassword("Please enter your password:") MsgBox "Your password is: " & strPw End Sub
代码的显示似乎有问题,我重发一下。顺便说明一下,如果你的机子上没装IE,那下面的代码就跳过吧! Rem 这就是传说中的带掩码的Inputbox,只是借了IE的壳出来亮亮相。 Function GetPassword(myPrompt)
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True On Error Resume Next Do While objIE.Document.All.OK.Value = 0 If Err Then IELogin = Array("", "") objIE.Quit Set objIE = Nothing Exit Function End If Loop On Error GoTo 0 GetPassword = objIE.Document.All.Password.Value objIE.Quit Set objIE = Nothing End FunctionRem 这句只是我拿来测试用的 Sub ShowTheInputbox() strPw = GetPassword("Please enter your password:") MsgBox "Your password is: " & strPw End Sub
上面那段代码中最后一个片段:Rem 这句只是我拿来测试用的 Sub ShowTheInputbox() strPw = GetPassword("Please enter your password:") MsgBox "Your password is: " & strPw End Sub由于我是在VB环境下运行,所以要用“Sub ... End Sub”将测试代码“strPw = ... Msgbox ...”包装起来。 如果楼主想在VBS环境下运行Msgbox等语句,只要把“Sub ... End Sub”的外衣去掉(注释掉)就行了。也就是:Rem 这句只是我拿来测试用的 Rem Sub ShowTheInputbox() strPw = GetPassword("Please enter your password:") MsgBox "Your password is: " & strPw Rem End Sub 其它的“Function ... End Function”的那部分代码保持不变就行。 刚刚又用楼主的方式测试了下,运行良好,不过就是慢了点。
设置为#,就显示成 ####
只能使用基本的VBA。。
还是谢谢大家回复
如果楼主还是不知怎做,那么可以这么做:
1. 楼主用的是什么软件的VBA,发出来大家研究一下。(不过VBA似乎都通用的,所以发不发都一样)
2. 在窗体初始化的过程中加入类似 TextBox1.Passwordchar="*" 的一句就行了。(首先假设输入框的控件名为TextBox1)
3. 如果楼主懒得加,那就乖乖的去找该控件的Passwordchar属性吧。注:该控件的Passwordchar不一定会显示在属性窗口中,所以还是建议用第2点的方法会方便很多。
里面只能写代码和调用其内部的变量。也没有相应的属性
感谢LS各位的回复
由于没用过NiceLabel,所以本人不知它的VBA跟Office VBA、AutoCAD VBA是否一样。不过,刚刚去NiceLabel看了下它的Programming Guide,发现有这么一句翻译成中文就是:
当你键入的关键字,然后按F1,将自动显示联机帮助。你完全可以通过对象浏览器和VBA帮助访问应用程序的对象模型。(看来楼主偷懒了,官方资料上白纸黑字写的很清楚呀。^_^)也就是说楼主你有3种选择:
1. 通过敲入关键字Passwordchar,再按F1,然后通过联机帮助了解Textbox是否有Passwordchar,或者有没其它控件可替代。
2. 通过VBA帮助Passwordchar。
3. 通过对象浏览器(这个可是VBA自带的,快捷键F2),在搜索栏里敲入Passwordchar,看看这个属性究竟是哪个控件的。如果用第3点,要注意的是:必须先建一个窗体,然后才能用对象浏览器找,否则可能找不到(这是在Office VBA中学到的一点经验,看看能不能用在NiceLabel上)。顺便问3句:
1. NiceLabel建窗体也只能用纯代码吗?还是说楼主忘了开工程管理器或属性窗口?
2. 楼主如何调用TextBox控件的?用CreateObject调用的吗?能否贴出来看看。
3. 楼主有没用TextBox.Passwordchar="*"这段代码试过?效果如何?给各反馈吧。
passowrdchar,没有任何结果。。如果我在NiceLabel中使用Prompt1.passwordchar= "*" (Note:Prompt1是我创建的一个变量,是一个text)
Error Code:
Error ID: 150603
Error description: 'The syntax validation of the script failed.'
Detailed information: 'Script error:
对象不支持此属性或方法: 'Prompt1.passwordchar'
Line number: 1'
Possible solution: ''
Severity ID: 3
Severity name: 'Error'
Available actions: OK
Default action: OK
Group ID: 17
Type ID: 2
Can disable dialog: NO
inputbox("please enter your name")
如果我输入"1234".怎么显示为“*”?多谢~~
参阅 示例 应用于 特性 指定在文本框中是显示占位符还是显示实际输入的字符。语法object.PasswordChar [= String]PasswordChar 属性的语法包括下列成分:成分 说明
object 必需。一个有效对象。
String 可选。字符串表达式,指定占位符。
说明可以用 PasswordChar 属性(例如密码或密码)保护机密的信息。PasswordChar 的值是显示在控件上的字符,而不是用户实际键入的字符。如果没有指定该字符,控件将显示用户实际键入的字符。
strPw = GetPassword("Please enter your password:")
MsgBox "Your password is: " & strPw
End SubFunction Password( myPrompt )
Dim objPassword
Set objPassword = CreateObject( "ScriptPW.Password" )
WScript.StdOut.Write myPrompt
Password = objPassword.GetPassword()
WScript.StdOut.Write String( Len( myPrompt ), Chr( 8 ) ) & Space( Len( myPrompt ) ) & String( Len( myPrompt ), Chr( 8 ) )
End Function
这是真正的VB代码哦。
'这就是传说中的带掩码的Inputbox,只是借了IE的壳出来亮亮相。Function GetPassword(myPrompt)
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Document.Title = "Password" & String(100, vbTab)
objIE.Toolbar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 320
objIE.Height = 180
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width) \ 2
objIE.Top = (.Availheight - objIE.Height) \ 2
End With
' Insert the HTML code to prompt for a password
objIE.Document.Body.InnerHTML = "<DIV ALIGN=""center""><P>" & myPrompt _
& "</P>" & vbCrLf _
& "<P><INPUT TYPE=""password"" SIZE=""20"" " _
& "ID=""Password""></P>" & vbCrLf _
& "<P><INPUT TYPE=""hidden"" ID=""OK"" " _
& "NAME=""OK"" VALUE=""0"">" _
& "<INPUT TYPE=""submit"" VALUE="" OK "" " _
& "OnClick=""VBScript:OK.Value=1""></P></DIV>"
objIE.Visible = True On Error Resume Next
Do While objIE.Document.All.OK.Value = 0
If Err Then 'user clicked red X (or alt-F4) to close IE window
IELogin = Array("", "")
objIE.Quit
Set objIE = Nothing
Exit Function
End If
Loop
On Error GoTo 0 GetPassword = objIE.Document.All.Password.Value objIE.Quit
Set objIE = Nothing
End Function'这句只是我拿来测试用的
Sub ShowTheInputbox()
strPw = GetPassword("Please enter your password:")
MsgBox "Your password is: " & strPw
End Sub
Rem 这就是传说中的带掩码的Inputbox,只是借了IE的壳出来亮亮相。
Function GetPassword(myPrompt)
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Document.Title = "Password" & String(100, vbTab)
objIE.Toolbar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 320
objIE.Height = 180
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width) \ 2
objIE.Top = (.Availheight - objIE.Height) \ 2
End With
objIE.Document.Body.InnerHTML = "<DIV ALIGN=""center""><P>" & myPrompt _
& "</P>" & vbCrLf _
& "<P><INPUT TYPE=""password"" SIZE=""20"" " _
& "ID=""Password""></P>" & vbCrLf _
& "<P><INPUT TYPE=""hidden"" ID=""OK"" " _
& "NAME=""OK"" VALUE=""0"">" _
& "<INPUT TYPE=""submit"" VALUE="" OK "" " _
& "OnClick=""VBScript:OK.Value=1""></P></DIV>"
objIE.Visible = True On Error Resume Next
Do While objIE.Document.All.OK.Value = 0
If Err Then
IELogin = Array("", "")
objIE.Quit
Set objIE = Nothing
Exit Function
End If
Loop
On Error GoTo 0 GetPassword = objIE.Document.All.Password.Value objIE.Quit
Set objIE = Nothing
End FunctionRem 这句只是我拿来测试用的
Sub ShowTheInputbox()
strPw = GetPassword("Please enter your password:")
MsgBox "Your password is: " & strPw
End Sub
我測試了,還是沒用。我是這樣做的,在桌面創建一個txt文本文件。然後複製你的代碼進去,關閉
修改後綴名為.vbs。然後雙擊打開,沒有任何反應。電腦當然有IE。IE:7.0.6000.17023
Sub ShowTheInputbox()
strPw = GetPassword("Please enter your password:")
MsgBox "Your password is: " & strPw
End Sub由于我是在VB环境下运行,所以要用“Sub ... End Sub”将测试代码“strPw = ... Msgbox ...”包装起来。
如果楼主想在VBS环境下运行Msgbox等语句,只要把“Sub ... End Sub”的外衣去掉(注释掉)就行了。也就是:Rem 这句只是我拿来测试用的
Rem Sub ShowTheInputbox()
strPw = GetPassword("Please enter your password:")
MsgBox "Your password is: " & strPw
Rem End Sub
其它的“Function ... End Function”的那部分代码保持不变就行。
刚刚又用楼主的方式测试了下,运行良好,不过就是慢了点。