过程里如何调用"引用"
///////////
Dim st, dataOff, imgW, imgH, imgWBytes, unitW, unitH
Set st = New ADODB.Stream
st.Type = 1
st.Mode = 3
st.Open
'加载图片二进制流,并读取图片头信息st.Close
.
.
..Function getBound(bp)
Dim str, i, ii
st.Position = bp ////////// 这里引用Position 就出错?为什么?
For i = 1 To unitH
For ii = 1 To unitW
If AscB(st.Read(1)) = 1 Then
str = str & "1"
Else
str = str & "0"
End If
Next
st.Position = bp - i * imgWBytes
Next
getBound = str
End Function
///////////
Dim st, dataOff, imgW, imgH, imgWBytes, unitW, unitH
Set st = New ADODB.Stream
st.Type = 1
st.Mode = 3
st.Open
'加载图片二进制流,并读取图片头信息st.Close
.
.
..Function getBound(bp)
Dim str, i, ii
st.Position = bp ////////// 这里引用Position 就出错?为什么?
For i = 1 To unitH
For ii = 1 To unitW
If AscB(st.Read(1)) = 1 Then
str = str & "1"
Else
str = str & "0"
End If
Next
st.Position = bp - i * imgWBytes
Next
getBound = str
End Function
可能是
set st.Position = bp
要求对像是VBS 里的代码,现在想在VB里运行
如上面的
set st.Position = bp
-------------------------
改为
Set st = CreateObject("ADODB.Stream")
///
实时错误'424'
要求对像
///
原代码如下:
Dim NumAry(9)
NumAry(0) = "00011000001111000110011011000011110000111100001111000011011001100011110000011000"
NumAry(1) = "00011000001110000111100000011000000110000001100000011000000110000001100001111110"
NumAry(2) = "00111100011001101100001100000011000001100000110000011000001100000110000011111111"
NumAry(3) = "01111100110001100000001100000110000111000000011000000011000000111100011001111100"
NumAry(4) = "00000110000011100001111000110110011001101100011011111111000001100000011000000110"
NumAry(5) = "11111110110000001100000011011100111001100000001100000011110000110110011000111100"
NumAry(6) = "00111100011001101100001011000000110111001110011011000011110000110110011000111100"
NumAry(7) = "11111111000000110000001100000110000011000001100000110000011000001100000011000000"
NumAry(8) = "00111100011001101100001101100110001111000110011011000011110000110110011000111100"
NumAry(9) = "00111100011001101100001111000011011001110011101100000011010000110110011000111100"Dim st, dataOff, imgW, imgH, imgWBytes, unitW, unitH
Set st = CreateObject("ADODB.Stream")
st.Type = 1
st.Mode = 3
st.open
st.LoadFromFile ("c:\1.bmp")
st.Position = 10
dataOff = BinVal(st.Read(4))
st.Read (4)
imgW = BinVal(st.Read(4))
imgH = BinVal(st.Read(4))
imgWBytes = imgW
unitW = 8
unitH = 10Dim i, ii, tmp, validCode
For i = 0 To 4
tmp = getBound(3188 + (unitW + 1) * i)
For ii = 0 To 9
If tmp = NumAry(ii) Then
validCode = validCode & ii
Exit For
End If
Next
If Len(validCode) = i Then validCode = validCode & "*"
Next
st.Close
Set st = Nothing
MsgBox ("验证码是:" & validCode)
End Sub
Function getBound(bp)
Dim str, i, ii
' Set st = New ADODB.Stream
st.Position = bp
For i = 1 To unitH
For ii = 1 To unitW
If AscB(st.Read(1)) = 1 Then
str = str & "1"
Else
str = str & "0"
End If
Next
st.Position = bp - i * imgWBytes
Next
getBound = str
End Function
Function BinVal(bin)
Dim ret
ret = 0
For i = LenB(bin) To 1 Step -1
ret = ret * 256 + AscB(MidB(bin, i, 1))
Next
BinVal = ret
End Function' ASCIIToByteArray converts ASCII strings to a byte array
' a byte array is different from an array of bytes, some things require
' a byte array, such as writing to the ADODB stream. This function
' utilises the ADODB ability to convert to byte arrays from dual digit HEX strings...
Function ASCIIToByteArray(sText)
Dim objRS
Dim lTemp
Dim sTemp sTemp = "" ' Convert the string to dual digit zero padded hex,
' there ain't no quick way of doing this... Would be interested to hear
' if anyone do this quicker...
For lTemp = 1 To LenB(sText)
sTemp = sTemp & Right("00" & Hex(AscB(MidB(sText, lTemp, 1))), 2)
Next ' Ok, this may look a little weird, but trust me, this works...
' Open us a recordset
Set objRS = WScript.CreateObject("ADODB.Recordset") ' Add a fields to the current recordset, add the hex string
objRS.Fields.Append "Temp", 204, LenB(sText) + 1
objRS.open
objRS.AddNew
objRS("Temp") = sTemp ' ADODB will convert here
objRS.Update
objRS.MoveFirst ASCIIToByteArray = objRS("Temp") ' A variant byte array is returned objRS.Close Set objRS = Nothing
End Function
Private Sub form_load() '<----------------------我了这句,因为不知道你的原来是写在什么事件里Dim NumAry(9)
NumAry(0) = "00011000001111000110011011000011110000111100001111000011011001100011110000011000"
NumAry(1) = "00011000001110000111100000011000000110000001100000011000000110000001100001111110"
NumAry(2) = "00111100011001101100001100000011000001100000110000011000001100000110000011111111"
NumAry(3) = "01111100110001100000001100000110000111000000011000000011000000111100011001111100"
NumAry(4) = "00000110000011100001111000110110011001101100011011111111000001100000011000000110"
NumAry(5) = "11111110110000001100000011011100111001100000001100000011110000110110011000111100"
NumAry(6) = "00111100011001101100001011000000110111001110011011000011110000110110011000111100"
NumAry(7) = "11111111000000110000001100000110000011000001100000110000011000001100000011000000"
NumAry(8) = "00111100011001101100001101100110001111000110011011000011110000110110011000111100"
NumAry(9) = "00111100011001101100001111000011011001110011101100000011010000110110011000111100"Dim dataOff, imgW, imgH, imgWBytes, unitW, unitH '<-----------------把这里的st的定义取消,然后把它定义为模块级变量
Set st = CreateObject("ADODB.Stream")
st.Type = 1.......
......
后面的代码一样,不用改
Dim NumAry(9)Private Sub form_load() '<----------------------我了这句,因为不知道你的原来是写在什么事件里
NumAry(0) = "00011000001111000110011011000011110000111100001111000011011001100011110000011000"
........NumAry(9) = "00111100011001101100001111000011011001110011101100000011010000110110011000111100"
Dim dataOff, imgW, imgH, imgWBytes, unitW, unitH '<-----------------把这里的st的定义取消,然后把它定义为模块级变量
Set st = CreateObject("ADODB.Stream")
st.Type = 1.......
......
后面的代码一样,不用改