不知道如何用vb6.0编写摩尔斯电码,题目比较麻烦,我的暑期任务,非常难搞,需要完整代码,谢谢。
2条回答 默认 最新
- 浪客 2022-07-16 09:14关注本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
供参考
Dim MorseArr() As String Dim strMorse As String Dim Char As String Private Sub Form_Load() strMorse = "·- -··· -·-· -·· · ··-· --· ···· ·· ·--- -·- ·-·· -- -· --- ·--· --·- ·-· ··· - ··- ···- ·-- -··- -·-- --·· " _ & "----- ·---- ··--- ···-- ····- ····· -···· --··· ---·· ----· " _ & "··--·· -··-· -·--·- -·--·- -····- ·-·-·-" MorseArr = Split(strMorse, " ") Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?/()-·" End Sub Function isMorse%(text$) isMorse = -1 m = 0 e = -1 For i = 0 To UBound(MorseArr) m = InStr(text, MorseArr(i)) If m > 0 Then Exit For End If Next i For i = 1 To Len(Char) - 2 e = InStr(text, Mid(Char, i, 1)) If e > 0 Then Exit For End If Next i If m > 0 And e > 0 Then isMorse = -1 ElseIf m > 0 And e = 0 Then isMorse = 1 ElseIf m = 0 And e > 0 Then isMorse = 2 End If End Function Function getM%(txt$) getM = -1 For i = 0 To UBound(MorseArr) If txt = MorseArr(i) Then getM = i Exit Function End If Next i End Function Function MtoE$(txt$) Dim sa() As String MtoE = "" txtarr = Split(txt, " ") For i = 0 To UBound(txtarr) s$ = txtarr(i) sa = Split(s, " ") For j = 0 To UBound(sa) inx = getM(sa(j)) If inx > -1 Then MtoE = MtoE & Mid(Char, inx + 1, 1) Next j MtoE = MtoE & " " Next End Function Function EtoM$(txt$) EtoM = "" slen = Len(txt) For i = 1 To slen s$ = Mid(txt, i, 1) If s = " " Then EtoM = EtoM & " " Else inx = InStr(Char, s) If inx > 0 Then EtoM = EtoM & MorseArr(inx - 1) & " " End If Next i End Function Private Sub Command1_Click() txt$ = UCase(Text1.text) inx = isMorse(txt) If inx = 1 Then txt = "摩尔斯代码" & vbCrLf & MtoE(txt) ElseIf inx = 2 Then txt = "英语短句" & vbCrLf & EtoM(txt) Else txt = "输入错误" End If Text2.text = txt End Sub
赞回复
悬赏问题
- ¥15 全志t113i启动qt应用程序提示internal error
- ¥15 ensp可以看看嘛.
- ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
- ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
- ¥15 minist数字识别
- ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
- ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
- ¥15 网上下载的3DMAX模型,不显示贴图怎么办
- ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
- ¥15 潜在扩散模型的Unet特征提取