商贾传奇全集在线收听:vb.net面试题,请大家帮忙,谢谢。

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 10:31:21
前三道我做的差不多了,实在实力有限,请大家帮忙啊,就这么多积分全拿出来了,谢谢了。
Question 4
In the following VB program, please states any potential problem(s) and how to correct.

Private Sub btnCalc_Click( )
Dim result As Integer
Try
Me.Cursor = Windows.Forms.Cursors.WaitCursor
result = Convert.ToInt32(txtInput1.Text) / Convert.ToInt32(txtInput2.Text)
txtResult.Text = result
Me.Cursor = Windows.Forms.Cursors.Default
Catch ex As Exception
MsgBox(ex.StackTrace)
Catch ex As ArgumentNullException
MsgBox("Input Test box cannot be null.")
Catch ex As OverflowException
MsgBox("Input Test box 2 cannot be zero!")
Catch ex As FormatException
MsgBox("Input Test box should be numeric format!")
End Try
End Sub

Question 5

GetRecordset() is a VB function that returns a ADODB.Recordset object:

Ref_ID Qty Price
Row 0 00123 1000 60.50
Row 1 00123 2000 60.00
Row 2 00123 3500 59.50
Row 3 00124 3000 60.50
Row 4 00125 2000 59.50
Row 5 00125 1000 58.00

(This recordset is sorted by Ref_ID)

The following program

Dim rst as ADODB.Recordset
Rst = GetRecordset
Do While Not rst.EOF
Console.writeline(rst.Fields("Ref_ID") & vbcrlf & rst.Fields("Qty") & vbcrlf & rst.Fields("Price"))
rst.MoveNext()
Loop

Can generate the following output:

Output:

00123 1000 60.50
00123 2000 60.00
00123 3500 59.50
00124 3000 60.50
00125 2000 59.50
00125 1000 58.00

Please suggest how to modify the above program to generate the following output:

Output:
00123
1000 60.50
2000 60.00
3500 59.50
---- -----
6500 60.00
00124
3000 60.50
---- -----
3000 60.50
00125
2000 59.50
1000 58.00
---- -----
3000 58.75

Question 6

Problem: Use your most hands-on programming language to implement a function that prints all possible combinations of the characters in a string. These combinations range in length from one to the length of the string. Two combinations that differ only in ordering of the characters ARE the same combination. In other words, “12” and “31” are different combinations from the input string “123”, but “21 is the same as “12”.

For example, if we use “wxyz” as parameter for Combination(“wxyz”) the function will print out

w
x
y
z
wx
wy
wz
xy
xz
yz
wxy
wxz
wyz
xyz
wxyz

Answer:

如果需要讲详细一点,那就加我QQ531412815

第4题,潜在的错误,这里的错误不是常规错误,属于那种只有在运行是才知道的错误:
Catch ex As Exception
MsgBox(ex.StackTrace)
'永远不会查找下面的错误
Catch ex As ArgumentNullException
MsgBox("Input Test box cannot be null.")
Catch ex As OverflowException
MsgBox("Input Test box 2 cannot be zero!")
Catch ex As FormatException
MsgBox("Input Test box should be numeric format!")
结构化错误处理永远达不到下面这里,因为Catch ex As Exception 已经处理了所有错误.

第5题:
00123
1000 60.50
2000 60.00
3500 59.50
---- -----
6500 60.00
00124
3000 60.50
---- -----
3000 60.50
00125
2000 59.50
1000 58.00
---- -----
3000 58.75
就是按照Ref_ID 分类,有一种方法就是按照Ref_ID 分组,也就是使用SQL语言,不过这里需要该很多,

我就不用了,那么就稍微复杂一点,使用FIND方法,不过有一点必须注意REF_ID必须排序,因为数据库中

已经排好序了,我就不用排了。
Dim rst as ADODB.Recordset
dim refID as string
Rst = GetRecordset
Do While Not rst.EOF
refid=rst(0)
Console.writeline(rst.Fields("Ref_ID")
do
Console.writeline rst.Fields("Qty") & vbcrlf & rst.Fields("Price"))
rst.MoveNext()
loop while rst(0)=refid
Loop

第6题:就是从一个集合中取元素输出的问题
比较简单的办法就是使用递归
以下是使用VB的方法(可以移植到VB.NET上,因为我对VB.NET的数组到现在还不太会,所以就将就一下)
Dim bUse() As Boolean
Dim lStr() As String * 1
Dim nCount As Byte
-----------------------------------------------------------------------------------
Public Sub Combination(lstStr As String)
Dim i As Byte
Dim j As Byte
Dim StrLen As Byte
StrLen = Len(lstStr)
ReDim bUse(1 To StrLen) As Boolean
ReDim lStr(1 To StrLen) As String * 1
For i = 1 To StrLen
lStr(i) = Mid(lstStr, i, 1)
Next
For i = 1 To StrLen
nCount = i
GoWith StrLen, 1, 0, ""
Next
End Sub
------------------------------------------------------------------------------------
Public Sub GoWith(ECount As Byte, nStart As Byte, Deep As Byte, lastStr As String)
Dim i As Byte
If Deep = nCount Then
Debug.Print lastStr
Exit Sub
End If

For i = nStart To ECount
If Not bUse(i) Then
bUse(i) = True
GoWith ECount, i, Deep + 1, lastStr & lStr(i)
bUse(i) = False
End If
Next

End Sub
--------------------------------------------------------------------------------------
Private Sub Form_Load()
Combination "wxyz"

End Sub
--------------------------------------------------------------------------------------
其中GOWITH是真正的递归函数,而Combination是用来预处理字符的
全局变量:
BUSE:用来确定是否使用过这个元素
lSTR:用来保存字符元素
NCOUNT:用来限制递归函数的深度,换句话说,就是输出元素组中的元素个数

实际测试成功,另外我对前三题很感兴趣,希望能够传给我

第4题,潜在的错误,这里的错误不是常规错误,属于那种只有在运行是才知道的错误:
Catch ex As Exception
MsgBox(ex.StackTrace)
'永远不会查找下面的错误
Catch ex As ArgumentNullException
MsgBox("Input Test box cannot be null.")
Catch ex As OverflowException
MsgBox("Input Test box 2 cannot be zero!")
Catch ex As FormatException
MsgBox("Input Test box should be numeric format!")
结构化错误处理永远达不到下面这里,因为Catch ex As Exception 已经处理了所有错误.

第5题:
00123
1000 60.50
2000 60.00
3500 59.50
---- -----
6500 60.00
00124
3000 60.50
---- -----
3000 60.50
00125
2000 59.50
1000 58.00
---- -----
3000 58.75
就是按照Ref_ID 分类,有一种方法就是按照Ref_ID 分组,也就是使用SQL语言,不过这里需要该很多,

我就不用了,那么就稍微复杂一点,使用FIND方法,不过有一点必须注意REF_ID必须排序,因为数据库中

已经排好序了,我就不用排了。
Dim rst as ADODB.Recordset
dim refID as string
Rst = GetRecordset
Do While Not rst.EOF
refid=rst(0)
Console.writeline(rst.Fields("Ref_ID")
do
Console.writeline rst.Fields("Qty") & vbcrlf & rst.Fields("Price"))
rst.MoveNext()
loop while rst(0)=refid
Loop

第6题:就是从一个集合中取元素输出的问题
比较简单的办法就是使用递归
以下是使用VB的方法(可以移植到VB.NET上,因为我对VB.NET的数组到现在还不太会,所以就将就一下)
Dim bUse() As Boolean
Dim lStr() As String * 1
Dim nCount As Byte
-----------------------------------------------------------------------------------
Public Sub Combination(lstStr As String)
Dim i As Byte
Dim j As Byte
Dim StrLen As Byte
StrLen = Len(lstStr)
ReDim bUse(1 To StrLen) As Boolean
ReDim lStr(1 To StrLen) As String * 1
For i = 1 To StrLen
lStr(i) = Mid(lstStr, i, 1)
Next
For i = 1 To StrLen
nCount = i
GoWith StrLen, 1, 0, ""
Next
End Sub
------------------------------------------------------------------------------------
Public Sub GoWith(ECount As Byte, nStart As Byte, Deep As Byte, lastStr As String)
Dim i As Byte
If Deep = nCount Then
Debug.Print lastStr
Exit Sub
End If

For i = nStart To ECount
If Not bUse(i) Then
bUse(i) = True
GoWith ECount, i, Deep + 1, lastStr & lStr(i)
bUse(i) = False
End If
Next

End Sub
--------------------------------------------------------------------------------------
Private Sub Form_Load()
Combination "wxyz"

End Sub

我好晕啊!
这么难,恐怕没多少 人回答吧
最好找个老师帮你

学过VB的人也看头大了。哈哈。。。
太难了吧。。。

我是学c#的,我看了一下
第4题是改错,错误应该出现在对异常的处理,可能是异常的类型错了(异常的类型与后续的处理不配套),你可以查一下异常的类型
第5题是关于数据库的,要求按Ref_ID分类,还要对各项求和用select语句试一下select Ref_ID,sum(Qty),sum(Price)
from 表名
group by Ref_ID
第六题可以用split函数将字符串分裂成数组,用两个循环就可以解决问题

头好大 我也做不出 我回去找人帮忙.......... :(