有人可以帮我PLZ [英] Someone can help me plz

查看:89
本文介绍了有人可以帮我PLZ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私有  Sub  Command1_Click()
Dim a,b,c 作为 整数
a = Text1.Text
b = Text2.Text
c = Text3.Text
如果 a = b 然后
如果 a = c 那么
MsgBox 三角形的类型是等边的
否则

MsgBox 三角形类型isoceles
结束 如果
ElseIf a = c 然后
MsgBox 三角形的类型是等于
ElseIf b = c 然后
MsgBox 三角形的类型是isoceles

否则
MsgBox 三角形的类型是倾斜的
结束 如果
结束 Sub





我尝试了什么:



当我运行程序时,此错误发生未找到方法或数据成员

解决方案

使用您共享的代码段获取该错误的唯一方法是if Text1 Text2 Text3 没有 Text 属性。目前还不清楚那些控件是什么意思,因为它们不是默认名称



您的代码还有其他问题:



1.为按钮和文本框使用合理的名称。你刚才可能记得Command1告诉你你描述了什么类型的三角形,但是当你在6个月后回到代码时,在你添加了功能之后 - 你还记得吗?尽快养成良好的习惯。



2.我认为你认为你用

  Dim  a,b,c 作为 整数 

但你可能会发现 a b 是Variants。尝试明确声明您的变量,例如

  Dim  a  As   Integer ,b 作为 整数,c  As  整数 





3.我不是粉丝单字母变量 - 尝试更具描述性



4.考虑行

 c = Text3.Text 

您将在该行上出现类型不匹配错误,因为 Text1.Text 是......呃......文本,字符串和 c 是一个整数。一些编译器让你逃脱它并为你做一个隐式转换,但如果你把文本框留空,编译器就无法应对。确保任何类型的更改都很明显,并且您的代码将更加健壮和便携,例如

 c = Val(Sheet1.Text3.Text)





解决以上所有问题之后什么都没有实际上你提供的代码错误,但请注意我上面使用了便携式这个词?如果您可以放弃使用VB6,那么您应该删除它并使用VB.NET(如果您愿意,还可以使用C#)。几十年来,微软并未支持VB6。如果你的学校坚持要你使用VB6,那就离开并把钱花在别的地方。



最后,尝试使用更有意义的标题来解决您的问题 - 大多数在QA上发帖的人都在寻求帮助:-)避免使用txt-speak(plz )如果你想被认真对待


你将变量声明为 Integer 但是要分配字符串。据我所知,VB6不支持将字符串隐式转换为数字类型。您必须首先使用 CInt()函数将字符串转换为整数:

 a =  CInt (Text1.Text)
b = CInt (Text2.Text)
c = CINT (Text3.Text)


Private Sub Command1_Click()
Dim a, b, c As Integer
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a = b Then
    If a = c Then
        MsgBox "type of triangle is equilateral"
    Else
         
        MsgBox "type of triangle is isoceles"
    End If
ElseIf a = c Then
    MsgBox "Type of triangle is isoceles"
ElseIf b = c Then
    MsgBox "Type of triangle is isoceles"
    
Else
    MsgBox "Type of triangle is oblique"
End If
End Sub



What I have tried:

when I run program this eror occur "method or data member not found"

解决方案

The only way you can get that error with the code snippet you have shared is if Text1, Text2 or Text3 do not have a Text property. It is unclear what controls those are meant to be as they are not the default names

There are other problems with your code:

1. Use sensible names for buttons and textboxes. You might be able to remember just now that Command1 tells you what type of triangle you have described, but when you come back to the code in 6 months time, after you've added functionality - will you still remember? Get into good habits as soon as possible.

2. I think that you think you have defined 3 integers with

Dim a, b, c As Integer

but you are probably going to find that a and b are Variants. Try explicitly declaring your variables e.g.

Dim a As Integer, b As Integer, c As Integer



3. I'm not a fan of single letter variables either - try to be more descriptive

4. Consider the line

c = Text3.Text

You're going to get a "Type Mismatch" error on that line because Text1.Text is ... er ... text, a string and c is an integer. Some compilers let you get away with it and make an implicit conversion for you but if you leave the textbox blank the compiler cannot cope. Make sure any change of type is obvious and your code will be more robust and portable e.g.

c = Val(Sheet1.Text3.Text)



After addressing all of the above there is nothing actually "wrong" with the code you have presented, but note I used the word "portable" above? If you can drop the use of VB6 then you should drop it and use VB.NET (or C# if you prefer). VB6 hasn't been suppported by Microsoft in decades. If your school insists on you using VB6 then leave and spend your money elsewhere.

Finally, try to use more meaningful titles for your questions - mostly everyone who posts in QA is looking for help :-) Avoid using "txt-speak" (plz) if you want to be taken seriously


You are declaring your variables as Integer but assign strings. As far as I remember, VB6 does not support implicit conversions for strings to numeric types. You have to convert the strings to integers first using the CInt() function:

a = CInt(Text1.Text)
b = CInt(Text2.Text)
c = CInt(Text3.Text)


这篇关于有人可以帮我PLZ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆