小弟的一个烂vb程序,希望哪位大哥可以看一看帮小弟解决,小弟不胜感激。

时间:2021-07-11 04:45:58
Function ispalindrome(text As String) As Boolean  '定义一个函数,判断一个数是不是回文

Dim tonumber, tostring, i%, temp1, temp2

tonumber = Val(text)

tostring = Str(tonumber)

i = 0

length = Len(tostring)

If length = 1 Then

ispalindrome = True

ElseIf length = 0 Then

ispalindrome = False

Else

Do

i = i + 1

temp1 = Mid(tostring, length + 1 - i, 1)

temp2 = Mid(tostring, i, 1)

Picture1.Print temp2    '这句是小弟调试时加的,不知道问什么temp2就是什么都不输出,
                                                     '而temp1就能输出,小弟想不通那是为什么,请大哥指点

Loop While (temp1 = temp2) And (i < (length + 1 - i))

    If temp1 <> temp2 Then
    
    ispalindrome = False
    
    Else
    
    ispalindrome = True
    
    End If
    
End If

End Function

Private Sub Text1_LostFocus()

If ispalindrome(Text1) Then

Picture1.Print Text1; "★"

Else

Picture1.Print Text1

End If

Text1 = ""

End Sub

8 个解决方案

#1


直接用VB自带函数判断
if tostring=StrReverse(tostring) then
  ? "回文"
else
  ? "不是回文"
endif

#2


csdn的引号问题解决了?
""
 " "  "

#3


对于你要的效果,1楼的答案你满意了没?




冒号的问题貌似是解决了!
但新的问题又多了!!
看你的答案,if……else……end if 之间有两个问号~
是你自己搞上去的还是我的机子有问题显示不了???
还有就是登陆问题,明明点了“2星期不用登陆”,但下次打开页面的时候,还是要登陆!
这个不算什么,最离谱的就是,明明在登陆的情况下,也没离开CSDN,但是在浏览帖子的时候却无端端要求重新登陆~~~

#4


顶三楼,我也遇见过这种情况。而且没有清清除浏览器的cookie,就提示重新登陆。

#5


问号"?" 在VB里面会自动转化成 Print 也就是把文字输出到窗口函数

#6


直接用VB自带函数判断 
if   tostring=StrReverse(tostring)   then 
    ?   "回文" 
else 
    ?   "不是回文" 
endif



我都不知道还有回文的自带函数,谢谢

可是用那个不行,题目要求自己写,还有我那个问题我就是搞不明白为什么
temp1 = Mid(tostring,length+1-i,1)这句为什么拿不出来字符呢?
temp1 = Mid(tostring,i,1)这句就好使。
请大家帮忙看看吧 

#7


帮你小修了下 

Function ispalindrome(text As String) As Boolean               '定义一个函数,判断一个数是不是回文

Dim tonumber%, tostring$, i%, temp1$, temp2$, length% '这里最好为每一个变量指定类型

tostring = text

i = 0

length = Len(tostring)

If length = 1 Then

ispalindrome = True

ElseIf length = 0 Then

ispalindrome = False

Else

Do

i = i + 1

temp1 = Mid(tostring, length + 1 - i, 1)

temp2 = Mid(tostring, i, 1)

'Picture1.Print temp2         '这句是小弟调试时加的,不知道问什么temp2就是什么都不输出,
                                                                                                          '而temp1就能输出,小弟想不通那是为什么,请大哥指点
Loop While (temp1 = temp2) And (i < (length + 1 - i))

        If temp1 <> temp2 Then
        
        ispalindrome = False
        
        Else
        
        ispalindrome = True
        
        End If
        
End If

End Function

#8


谢谢,辛苦啦。
运行成功了

我好象多了
tonumber   =   Val(text) 
tostring   =   Str(tonumber) 
这两句
 

#1


直接用VB自带函数判断
if tostring=StrReverse(tostring) then
  ? "回文"
else
  ? "不是回文"
endif

#2


csdn的引号问题解决了?
""
 " "  "

#3


对于你要的效果,1楼的答案你满意了没?




冒号的问题貌似是解决了!
但新的问题又多了!!
看你的答案,if……else……end if 之间有两个问号~
是你自己搞上去的还是我的机子有问题显示不了???
还有就是登陆问题,明明点了“2星期不用登陆”,但下次打开页面的时候,还是要登陆!
这个不算什么,最离谱的就是,明明在登陆的情况下,也没离开CSDN,但是在浏览帖子的时候却无端端要求重新登陆~~~

#4


顶三楼,我也遇见过这种情况。而且没有清清除浏览器的cookie,就提示重新登陆。

#5


问号"?" 在VB里面会自动转化成 Print 也就是把文字输出到窗口函数

#6


直接用VB自带函数判断 
if   tostring=StrReverse(tostring)   then 
    ?   "回文" 
else 
    ?   "不是回文" 
endif



我都不知道还有回文的自带函数,谢谢

可是用那个不行,题目要求自己写,还有我那个问题我就是搞不明白为什么
temp1 = Mid(tostring,length+1-i,1)这句为什么拿不出来字符呢?
temp1 = Mid(tostring,i,1)这句就好使。
请大家帮忙看看吧 

#7


帮你小修了下 

Function ispalindrome(text As String) As Boolean               '定义一个函数,判断一个数是不是回文

Dim tonumber%, tostring$, i%, temp1$, temp2$, length% '这里最好为每一个变量指定类型

tostring = text

i = 0

length = Len(tostring)

If length = 1 Then

ispalindrome = True

ElseIf length = 0 Then

ispalindrome = False

Else

Do

i = i + 1

temp1 = Mid(tostring, length + 1 - i, 1)

temp2 = Mid(tostring, i, 1)

'Picture1.Print temp2         '这句是小弟调试时加的,不知道问什么temp2就是什么都不输出,
                                                                                                          '而temp1就能输出,小弟想不通那是为什么,请大哥指点
Loop While (temp1 = temp2) And (i < (length + 1 - i))

        If temp1 <> temp2 Then
        
        ispalindrome = False
        
        Else
        
        ispalindrome = True
        
        End If
        
End If

End Function

#8


谢谢,辛苦啦。
运行成功了

我好象多了
tonumber   =   Val(text) 
tostring   =   Str(tonumber) 
这两句