VB程序员博客
02 1st, 2010
据说java语言是这样的,那VB呢?
byte[] b(byte)0×62,(byte)0×11,(byte)0×72,(byte)0×31};
try {
System.out.println(new String(b,"UTF-16"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
可以借助 ADO.Stream。
通过修改 CharSet 可以变成 UTF-16 的转换。
见http://topic.csdn.net/u/20090925/20/2e5e73c8-d92a-4c10-9650-bb81736b6476.html
楼主我来帮你顶!
01 31st, 2010
有点急~~谢谢各位~~
VB6.0的代码怎样转换到VB2008上
要看具体的代码,不是能够100%转换的。
http://topic.csdn.net/u/20100116/10/a8ca2cf7-4b9e-4cbe-bc98-9b8c338a1656.html
Private Sub Command2_Click()
Dim a, b, c
Do
a = Int(Rnd * 12) + 1
b = Int(Rnd * 12) + 1
c = Int(Rnd * 12) + 1
If a / b = c Then
Debug.Print a; "㷦quot;; b; "="; c
Exit Do
End If
Loop
End Sub
Private Sub Form_Load()
Randomize Timer
End Sub
以上是vb6.0的code 我在VB2008里那个Debug.Print a; "㷦quot;; b; "="; c中的 a; 下面有错误线提示
还有那个 Randomize Timer 中的Timer也有,谢谢帮忙~~~ 这是个关于被除数,除数,商都是1-12的整数,也就是说被除数一定能被除数整除,就像4除以2等于2,12除以6等于2
是在VB2008里,谢谢 帮忙~~~~
If RadioButton4.Checked = True Then
Dim a = TextBox1.Text, b = TextBox2.Text, c = TextBox4.Text
Do
a = Int(Rnd() * 12) + 1
b = Int(Rnd() * 12) + 1
c = Int(Rnd() * 12) + 1
If a / b = c Then
Debug.Print("{0}㷻1}={2}", a, b, c)
Exit Do
End If
Loop
End If
以上这种情况我运行了 没数在textbox里啊
If RadioButton4.Checked = True Then
TextBox1.Text = Int((12 * Rnd()) + 1)
TextBox2.Text = Int((12 * Rnd()) + 1)
Dim a = TextBox1.Text, b = TextBox2.Text, c = TextBox4.Text
Do
a = Int(Rnd() * 12) + 1
b = Int(Rnd() * 12) + 1
c = Int(Rnd() * 12) + 1
If a / b = c Then
Debug.Print("{0}㷻1}={2}", a, b, c)
Exit Do
End If
Loop
End If
这种情况有数 但被除数不能被除数刚好整除 谢谢~~~
这个跟转换代码有关系么?
没有~~但~~我最终要解决的就是这个整除问题~~大哥,你能帮上忙吗? 我先把代码的分给你。 谢谢你~~~
“VB中怎样使被除数,除数,商都是1-12的整数” 这是我发的帖~~
01 7th, 2009
小弟最近要用一个DES算法,有VC++代码,但小弟只会VB,那位大哥帮忙转一下或是把这个算法生成DLL库,以下是代码
// Des.cpp: implementation of the CDes class.
#include "stdafx.h"
#include "Des.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
uchar res_codage[8];
uchar res_decodage[8];
static unsigned char Key[64];
static unsigned char input[64], /* data input */
output[64]; /* data output */
static unsigned char Kn[16][48];
static unsigned char T1[] = {
57,49,41,33,25,17, 9, 1,
59,51,43,35,27,19,11, 3,
61,53,45,37,29,21,13, 5,
63,55,47,39,31,23,15, 7,
56,48,40,32,24,16, 8, 0,
58,50,42,34,26,18,10, 2,
60,52,44,36,28,20,12, 4,
62,54,46,38,30,22,14, 6
};
static unsigned char T2[] = {
39, 7,47,15,55,23,63,31,
38, 6,46,14,54,22,62,30,
37, 5,45,13,53,21,61,29,
36, 4,44,12,52,20,60,28,
35, 3,43,11,51,19,59,27,
34, 2,42,10,50,18,58,26,
33, 1,41, 9,49,17,57,25,
32, 0,40, 8,48,16,56,24
};
static unsigned char T3[] = {
31, 0, 1, 2, 3, 4,
3, 4, 5, 6, 7, 8,
7, 8, 9,10,11,12,
11,12,13,14,15,16,
15,16,17,18,19,20,
19,20,21,22,23,24,
23,24,25,26,27,28,
27,28,29,30,31, 0
};
static unsigned char T5[] = {
15, 6,19,20,
28,11,27,16,
0,14,22,25,
4,17,30, 9,
1, 7,23,13,
31,26, 2, 8,
18,12,29, 5,
21,10, 3,24
};
static unsigned char T7_1_2[56] =
{
56,48,40,32,24,16, 8,
0,57,49,41,33,25,17,
9, 1,58,50,42,34,26,
18,10, 2,59,51,43,35,
62,54,46,38,30,22,14,
6,61,53,45,37,29,21,
13, 5,60,52,44,36,28,
20,12, 4,27,19,11, 3
};
static unsigned char T8[] =
{
0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0
};
static unsigned char T9[] =
{
13,16,10,23, 0, 4,
2,27,14, 5,20, 9,
22,18,11, 3,25, 7,
15, 6,26,19,12, 1,
40,51,30,36,46,54,
29,39,50,44,32,47,
43,48,38,55,33,52,
45,41,49,35,28,31
};
static unsigned char T6[][64] =
{
/* S1 */
{
14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13
},
/* S2 */
{
15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9
},
/* S3 */
{
10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12
},
/* S4 */
{
7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14
},
/* S5 */
{
2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3
},
/* S6 */
{
12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13
},
/* S7 */
{
4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12
},
/* S8 */
{
13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11
}
};
static unsigned char TE[][4] =
{
{0,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0},
{0,1,0,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,0},
{1,0,0,1},
{1,0,1,0},
{1,0,1,1},
{1,1,0,0},
{1,1,0,1},
{1,1,1,0},
{1,1,1,1}
};
void xor(uchar *a,uchar *b,int lg)
{
for (;lg–;) *a++ ^= *b++;
}
static void Ks(uchar *Key, uchar Kn[16][48])
{
uchar cd[56];
uchar zt[60] ;
int n;
unsigned char tmp11, tmp12, tmp21, tmp22;
int i;
unsigned char *Knn;
/* choix 1 */
for (i = 0; i < 56; i++)
{
cd[i] = Key[T7_1_2[i]];
}
for (n = 0; n < 16; n++)
{
if (T8[n] == 0)
{
tmp11 = cd[0];
tmp21 = cd[28];
memcpy( zt , &cd[1] , 55 );
memcpy( cd , zt , 55 );
cd[27] = tmp11;
cd[55] = tmp21;
}
else
{
tmp11 = cd[0];
tmp12 = cd[1];
tmp21= cd[28];
tmp22 = cd[29];
memcpy( zt , &cd[2] , 54 );
memcpy( cd , zt , 54 );
cd[26] = tmp11;
cd[27] = tmp12;
cd[54] = tmp21;
cd[55] = tmp22;
}
Knn = Kn[n];
for (i = 0; i < 48; i++)
{
Knn[i] = cd[T9[i]];
}
}
}
static void fonction(uchar *Knn, uchar *r, uchar *s)
{
unsigned char x[32];
unsigned long *px;
int i, l;
unsigned char c;
unsigned char t;
for (i = 0, l = 0, px = (unsigned long *) x; i < 8;)
{
c = 32 * (r[T3[l]] ^ Knn[l]);
l++;
c += 8 * (r[T3[l]] ^ Knn[l]);
l++;
c += 4 * (r[T3[l]] ^ Knn[l]);
l++;
c += 2 * (r[T3[l]] ^ Knn[l]);
l++;
c += 1 * (r[T3[l]] ^ Knn[l]);
l++;
c += 16 * (r[T3[l]] ^ Knn[l]);
l++;
t = T6[i][c];
i++;
*px = *(long *)TE[t];
px++;
}
for (i = 0; i < 32; i++)
{
s[i] = x[T5[i]];
}
}
static void permutation(uchar *org, uchar *tab)
{
unsigned char tmp[64];
int i;
memcpy(tmp, org, 64);
for (i = 0; i < 64; i++)
{
org[i] = tmp[tab[i]];
}
}
static void chiffrement(uchar *xi, uchar *xo, unsigned char Kn[16][48])
{
unsigned char r[32], l[32];
unsigned char rp[32], lp[32];
int i;
int n;
memcpy(l, &xi[0], 32);
memcpy(r, &xi[32], 32);
for (n = 0; n < 16; n++)
{
memcpy(lp, r, 32);
fonction(Kn[n], r, rp);
for (i = 0; i < 32; i++)
{
r[i] =( ( l[i]) ^ (rp[i] ) ) ;
}
memcpy(l, lp, 32);
}
memcpy(&xo[0], r, 32);
memcpy(&xo[32], l, 32);
}
static void dechiffrement(uchar *xi, uchar *xo, unsigned char Kn[16][48])
{
unsigned char r[32], l[32], rp[32], lp[32];
int i;
int n;
memcpy(l, &xi[0], 32);
memcpy(r, &xi[32], 32);
for (n = 0; n < 16; n++)
{
memcpy(lp, r, 32);
fonction(Kn[15 - n], r, rp);
for (i = 0; i < 32; i++)
{
r[i] =( ( l[i] ) ^ ( rp[i] )) ;
}
memcpy(l, lp, 32);
}
memcpy(&xo[0], r, 32);
memcpy(&xo[32], l, 32);
}
static void eclater(uchar *buf_bit, uchar *byte)
{
int i;
unsigned char m;
for (i = 0; i < 8; i++)
{
for (m = 0×80; m != 0; )
{
if ((buf_bit[i] & m) != 0)
*byte = 1;
else
*byte = 0;
byte++;
m=m/2 ;
}
}
}
static void compacter(uchar *byte, uchar *buf_bit)
{
int i;
unsigned char m, n;
for (i = 0; i < 8; i++)
{
n = 0;
for (m = 0×80; m != 0; )
{
if (*byte++)
n = n | m;
m=m/2 ;
}
buf_bit[i] = n;
}
}
void des(uchar *binput, uchar *boutput, uchar *bkey)
{
eclater(binput, input);
eclater(bkey, Key);
Ks(Key, Kn);
permutation(input, T1);
chiffrement(input, output, Kn);
permutation(output, T2);
compacter(output, boutput);
}
void desm1(uchar *binput, uchar *boutput, uchar *bkey)
{
eclater(binput, input);
eclater(bkey, Key);
Ks(Key, Kn);
permutation(input, T1);
dechiffrement(input, output, Kn);
permutation(output, T2);
compacter(output, boutput);
}
static uint minin(uint a,uint b)
{
if (a>=b)
return(b);
else
return(a);
}
void doubleEncrypt(uchar *in, uchar *out, uchar *key)
{
des(in,out,key);
desm1(out,out,&key[8]);
des(out,out,key);
}
可以帮把这个算法生成dll吗?
然后我就可以调用,谢谢
我的帖子要沉到底了吗?各位大虾帮帮忙,小弟急用
友情up
11 20th, 2008
在一个COMBO里面有“大于”的值,但是在SQL里面要用>来表示,但是如何将这个字符串的>转换为运算符的>.谢谢
dim strOp as string
select case COMBO.text
case "大于"
strop=">"
case "小于"
strop=" <"
…
end select
Sql="select * table where id " & strop & " 10"
11 20th, 2008
'TEXT中的转换
'当text1中输入的是小写的时候执行command将text1中的小写字母转换成大写
'当text1中输入的是大写的时候执行command将text1中的大写字母转换成小写
'只用一个命令按钮,帮忙看下下面的代码怎么不行,高手帮忙改改啊。
Private Sub Command1_Click()
If KeyAscii > 64 And KeyAscii < 91 Then KeyAscii = KeyAscii + 32
Text1.Text = LCase(Text1.Text)
If KeyAscii > 96 And KeyAscii < 123 Then KeyAscii = KeyAscii - 32
Text1.Text = UCase(Text1.Text)
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim s As String
Dim strText As String
For i = 1 To Len(Text1)
s = Mid(Text1, i, 1)
If Asc(s) > 64 And Asc(s) < 91 Then
s = Chr(Asc(s) + 32)
ElseIf Asc(s) > 96 And Asc(s) < 123 Then
s = Chr(Asc(s) - 32)
End If
strText = strText & s
Next
Text1 = strText
End Sub
我把一个结构体变量用CopyMemory转撚到一个BYTE数组里
再从这个BYTE数组里还原出这个结构体
type xxx
x1 as string * 10
x2 as string *10
end type
假设定义A是上面的结构体变量
赋值A.x1="123" A.x2="abc"
将A转换为BYTE数组再还原到同一结构体变量B中
debug.print B.x1得到“1 2 3 ”(中间有空格)
B.x2也是如此
若A.x1="1234567890"
则转换后debug.print B.x2输出结果为“1 2 3 4 5 ”超过10个字符后面自动被截断
不知道是什么原因造成的,用LenB()得出A和B的字节长度是一致的。
在线等答案!先谢谢各位了
x1 as string * 10 //我想是这里的问题: 这个不是指保存数据的长度(主要在这里出现了分歧)
X1="12345" (48 49 50 51 52)
而内存里面是 (00 48 00 49 00 50 00 51 00 52)
按塞北雪貂的代码偶改了一下。可以正常转换
偶以前用的计算长度用的是LenB()。改成Len就可以了
看了雪情的解释茅厕顿开
谢谢两位
10 17th, 2008
Dim Wname(20) As Byte '存储人物名称
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If hProcess Then
ReadProcessMemory hProcess, ByVal base + &H80, Wname(0), 20, 0& '得到人物名称
Label1.Caption = "角色名:" & StrConv(Wname, vbUnicode) '显示人名
在此谢过啦!!
StrConv(Wname, vbUnicode)
这个好像不能转出中文吧,你试试:StrConv(Wname, vbWide)
还有就是你debug.print所有Wname数组的值看看,然后你再chrW()看看它是什么字.
楼上的那个也显示不了,不过还是谢谢了,还是用回以前那个才解决
Dim Wname(20) As Byte '存储人物字符串
ReadProcessMemory hProcess, ByVal base - &H30, Wname(0), 20, 0& '得到人物20字节字符串
Label1.Caption = "角色名:" & StrConv(Wname, vbUnicode)
还是偏移没做好的问题,所以分还是散给你们二位热心前辈啦 ~_~
按理说用 vbUnicode 是对的.可能是你的字符串有问题.
10 15th, 2008
VB BMP 格式文件 转换为 JPG 支持命令行,批处理
命令行格式: image.exe [File1][分隔符][File2]
参数说明:
[File1] 要转换的文件(包含绝对路径 c:abc.bmp)
[分隔符] 可以是任何1位字符 [ ][,][;][!][a][A]
[File2] 目标文件(转换后生成的文件 d:aaaabc.jpg)
例:
image.exe c:abc.bmp 'File2 默认File1 路径及文件名只是格式为JPG
image.exe c:abc.bmp,d:aaaabc.jpg ' 转换后文件保存d:aaa下 如果d:aaa文件夹不存在自动创建
注: 支持鼠标拖动转换.把要转换的BMP格式文件的图片用鼠标左键按着不放,拖动到Image.exe 文件上就可完成转换.
命令行暂时不支持批处理.
莫名其妙
楼主真是高手,还支持命令行!
我自己写的.想与大家分享分享.
膜拜楼主 嘿嘿
我能做,¥300,peakplum@163.com
10 7th, 2008
字符串转换函数 str 与 cstr 有什么不同呢 其外好几个字符串函数还有,但是都是一样吗
当使用 str 时:
当一数字转成字符串时,总会在前头保留一空位来表示正负。如果 number 为正,返回的字符串包含一前导空格暗示有一正号。
而CStr时
将内容转换为字符串.
示例:
Str(123)= " 123" '前面有空格,因为是正确,前面一个空格表示符号位.
Cstr(123)="123" '前面没有空格
Str(-123)="-123" '前面没有空格.因为有一个负号
10 2nd, 2008
//已经实现在同一个文件中记录当前时间,并记录对网站的ping记录情况。
//现在需要第一次循环记录在com1.txt文件中,第二次文件记录在com2.txt文件中,依次类推,请问该如何做?
for i = 1 to 10 '10为重复的次数
WScript.Sleep(1000*60*60) '每60分钟一次
Set objShell = CreateObject("Wscript.Shell")
'objShell.Run("%windir%system32cmd"&" /c "& "date/t "&">>com.txt"), 0, TRUE
objShell.Run("%comspec% /c date/t "&">>com.txt"), 0, TRUE
objShell.Run("%comspec% /c time/t "&">>com.txt"), 0, TRUE
objShell.Run("%comspec% /c ping www.sina.com -n 10 "&">>com.txt"), 0, TRUE
objShell.Run("%comspec% /c ping www.tom.com -n 10 "&">>com.txt"), 0, TRUE
next
同上
如需要阅读该回复,请