VB总是弹出"变量未定义"

a506556425 2008-02-24 02:41:23
我在vb输入:
Private Sub 打开_Click()
CommonDialog3.FileName = ""
CommonDialog3.Flags = 4096
CommonDialog3.ShowOpen
CommonDialog3.Filter = "all files|*.*|(*.TXT)|*.TXT|(*.DOC)|*.DOC"
CommonDialog3.FilterIndex = 3
CommonDialog3.DialogTitle = "打开"
CommonDialog3.Action = 1
If CommonDialog3 = "" Then
MsgBox "No file selectd", 37, "Checking"
Else
'对所选择的文件进行处理
Open CommonDialog3.FileName For Input As #1
Do While Not EOF(1)
Input #1, a$
Print a$
Loop
End If
End Sub
VB总是弹出"变量未定义",Input #1, a$
Print a$
变成了红色.这是为什么?我可是按照书上说的来做的.
...全文
817 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
w237872018 2011-07-18
  • 打赏
  • 举报
回复
print a $
定义a为字符串,需要中间空格出来……
a506556425 2008-02-26
  • 打赏
  • 举报
回复
谢谢
qiu5208 2008-02-26
  • 打赏
  • 举报
回复
你用是的vb6吧,如果是用vb.net那这本书根本没用。

你的vb6中强制要求声明,

有两中方法解决,
1,在代码开头加入,dim a as string
然后把 Input #1, a$
Print a$
改成Input #1, a
Print a

2,把你程式码开头的Option Explicit 去掉。
Alices 2008-02-26
  • 打赏
  • 举报
回复
Print a$ ????
请问一下你VB是什么版的啊?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N年前的书吧,记得是QBASIC时用过
现在都用console.writeline OR console.write了
还有打开文件:
//VB.NET 2008

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strm As IO.StreamReader
Dim strall As String = String.Empty

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strm = New IO.StreamReader(OpenFileDialog1.OpenFile(), System.Text.Encoding.GetEncoding("gb2312"))
strall = strm.ReadToEnd
console.writeline(strall)
End If
End Sub
hskshk 2008-02-25
  • 打赏
  • 举报
回复
书上不一定都是对的
现在有好多垃圾书

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧