急!!! 老板让我今天完成任务可现在还没高手回答!文本中的数据变换问题,怎么没人回答啊,在线等待高手们的回答!!!!!!多谢!!!!

mss 2003-12-23 07:18:24
第一个文本框中的数据如下:
DB 040,020,0F8,017,002,0F8,04C,04B,
DB 000,000,0FF,000,02A,02A,016,015,
转变成下面格式(也就是从上面数中,间隔的取数 即:每取一个数加上H,然后隔一个再取组成第一行剩下的组成第二行),用第二个文本框显示出来,如下所示,
DB 040H,0F8H,002H,04CH,000H,0FFH,02AH,016H,
DB 020H,017H,0F8H,04BH,000H,000H,02AH,015H,

也就是用第一个文本框显示上面的数据,怎么转变让第二个文本框显示下面的数据

?????????????????????????????????????????
艾!就要交任务了现在还没搞出来,请大侠帮助帮助拉,多谢!!!
?????????????????????????????????????????
我就是用split,可用不好,现在还是有问题,能帮我写一下代码吗?多谢!!!!!!!!

...全文
8 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kang哥 2003-12-26
Private Sub Command1_Click()
Dim tempstr As String, s1() As String, s2() As String, s3() As String
Dim s4 As String, s5 As String, s6 As String, s7 As String
Dim i As Integer
tempstr = Replace(Text1, ",", "H,")
tempstr = Trim(Replace(tempstr, "DB", ""))
s1 = Split(tempstr, vbCrLf)
s2 = Split(s1(0), ",")
s3 = Split(s1(1), ",")
For i = 0 To UBound(s2) - 1 Step 2
s4 = s4 + Trim(s2(i)) + ","
s5 = s5 + Trim(s2(i + 1)) + ","
s6 = s6 + Trim(s3(i)) + ","
s7 = s7 + Trim(s3(i + 1)) + ","
Next i
tempstr = "DB " + s4 + s6 + vbCrLf + "DB " + s5 + s7
Text2 = tempstr
End Sub

Private Sub Form_Load()
Text1 = "DB 040,020,0F8,017,002,0F8,04C,04B," + vbCrLf + "DB 000,000,0FF,000,02A,02A,016,015,"
Text2 = ""
End Sub
回复
jone999 2003-12-24
通过文件来处理试试
回复
rainstormmaster 2003-12-24
呵呵,代码够长的:
先用api依次取出各行后再用split分割

回复
northwolves 2003-12-24
Private Sub Command1_Click()
Dim temp, temp1, temp2, temp3, strtemp As String, i As Long
temp = Split(Text1.Text, vbCrLf)
temp1 = Split(Split(temp(0), " ")(1), ",")
temp2 = Split(Split(temp(1), " ")(1), ",")
temp3 = Split(Split(temp(0), " ")(1) & Split(temp(1), " ")(1) & ",", ",")
For i = 0 To UBound(temp3)
If i Mod 2 = 0 Then
temp1(i / 2) = IIf(temp3(i) = "", "", temp3(i) & "H")
Else
temp2((i - 1) / 2) = IIf(temp3(i) = "", "", temp3(i) & "H")
End If
Next
strtemp = Split(temp(0), " ")(0) & " " & Join(temp1, ",") & vbCrLf & Split(temp(0), " ")(0) & " " & Join(temp2, ",")
Text2.Text = strtemp
End Sub

Private Sub Form_Load()
Text1.Text = "DB 040,020,0F8,017,002,0F8,04C,04B," & vbCrLf & "DB 000,000,0FF,000,02A,02A,016,015,"
Text2.Text = ""
End Sub
回复
mss 2003-12-23
leolan(leolan)你好!
你做的和我要求的不一样吧兄弟!
第一个文本框是:(这是已知的)
DB 040,020,0F8,017,002,0F8,04C,04B,
DB 000,000,0FF,000,02A,02A,016,015,
所求的要求在另一个文本框中显示,所求结果为:
DB 040,0F8,002,04C,000,0FF,02A,016,
DB 020,017,0F8,04B,000,000,02A,015,
回复
leolan 2003-12-23
剛剛有點筆誤,*^_^*
這回不會了,明天過關沒問題了,呵呵~

Option Explicit
Private m_str1 As String
Private m_str2 As String

Private Sub Command1_Click()
Dim l_arr1() As String
Dim l_arr2() As String
Dim l_strDB1 As String
Dim l_strDB2 As String
Dim i As Integer

m_str1 = Left(m_str1, Len(m_str1) - 1)
m_str2 = Left(m_str2, Len(m_str2) - 1)
l_arr1 = Split(m_str1, ",")
l_arr2 = Split(m_str2, ",")
For i = 0 To UBound(l_arr1)
If i Mod 2 = 0 Then
l_strDB1 = l_strDB1 & "," & l_arr1(i)
Else
l_strDB2 = l_strDB2 & "," & l_arr1(i)
End If
Next
For i = 0 To UBound(l_arr1)
If i Mod 2 = 0 Then
l_strDB1 = l_strDB1 & "," & l_arr2(i)
Else
l_strDB2 = l_strDB2 & "," & l_arr2(i)
End If
Next
l_strDB1 = Right(l_strDB1, Len(l_strDB1) - 1) & ","
l_strDB2 = Right(l_strDB2, Len(l_strDB2) - 1) & ","
Text1.Text = l_strDB1
Text2.Text = l_strDB2
End Sub

Private Sub Form_Load()
m_str1 = "040,020,0F8,017,002,0F8,04C,04B,"
m_str2 = "000,000,0FF,000,02A,02A,016,015,"
Text1.Text = m_str1
Text2.Text = m_str2
End Sub
回复
flc 2003-12-23
算法很简单的,实现起来也不太麻烦的吧……
回复
leolan 2003-12-23
Private m_str1 As String
Private m_str2 As String

Private Sub Command1_Click()
Dim l_arr1() As String
Dim l_arr2() As String
Dim l_strDB1 As String
Dim l_strDB2 As String
Dim i As Integer

m_str1 = Left(m_str1, Len(m_str1) - 1)
m_str2 = Left(m_str2, Len(m_str2) - 1)
l_arr1 = Split(m_str1, ",")
l_arr2 = Split(m_str2, ",")
For i = 0 To UBound(l_arr1)
If i Mod 2 = 0 Then
l_strDB1 = l_strDB1 & "," & l_arr1(i)
Else
l_strDB2 = l_strDB2 & "," & l_arr1(i)
End If
Next
For i = 0 To UBound(l_arr1)
If i Mod 2 = 0 Then
l_strDB1 = l_strDB1 & IIf(Len(l_strDB1) > 0, ",", "") & l_arr2(i) '& "," & l_arr2(i)
Else
l_strDB2 = l_strDB2 & IIf(Len(l_strDB1) > 0, ",", "") & l_arr2(i) '& "," & l_arr2(i)
End If
Next
l_strDB1 = Right(l_strDB1, Len(l_strDB1) - 1) & ","
l_strDB2 = Right(l_strDB2, Len(l_strDB2) - 1) & ","
Text1.Text = l_strDB1
Text2.Text = l_strDB2
End Sub

Private Sub Form_Load()
m_str1 = "040,020,0F8,017,002,0F8,04C,04B,"
m_str2 = "000,000,0FF,000,02A,02A,016,015,"
Text1.Text = m_str1
Text2.Text = m_str2
End Sub
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告