vb程序:在文本框中输入一个点坐标(x,y)怎样从文本框中分离出x,y,并判断是哪个象限
展开全部
建议你用两个文本框,并设定只能输入数字,这比从一个文本框输入后进行文本处理要简单实用很多,在一个文本框录入可以写一个分离函数,原理是: 取 ( 到 , 之间的内容为 x 取 , 到 ) 之间的内容 y
一个简单的实例:
Private Sub Form_Load()
Dim X As Long, Y As Long, bln As Boolean
bln = 取XY值("(32,33)", X, Y)
MsgBox "(32,33) X=" & X & " ,Y= " & Y
MsgBox 判断象限(X, Y)
End Sub
Public Function 取XY值(ByVal 要处理的文本 As String, ByRef X As Long, ByRef Y As Long) As Boolean
Dim A As Long, B As Long, C As Long, StrX As String, StrY As String
A = InStr(要处理的文本, "(")
B = InStr(要处理的文本, ",")
C = InStr(要处理的文本, ")")
StrX = Mid(要处理的文本, A + 1, B - A)
StrY = Mid(要处理的文本, B + 1, C - B - 1)
X = CLng(StrX)
Y = CLng(StrY)
取XY值 = True
End Function
Public Function 判断象限(X As Long, Y As Long) As String
Dim Xr As Integer, Yr As Integer
Xr = Sgn(X)
Yr = Sgn(Y)
Select Case Xr & Yr
Case "00"
判断象限 = "原点"
Case "01"
判断象限 = "Y正半轴"
Case "10"
判断象限 = "X正半轴"
Case "0-1"
判断象限 = "Y负半轴"
Case "-10"
判断象限 = "X负半轴"
Case "11"
判断象限 = "第一象限"
Case "-11"
判断象限 = "第二象限"
Case "-1-1"
判断象限 = "第三象限"
Case "1-1"
判断象限 = "第四象限"
Case Else
判断象限 = "出错了."
End Select
End Function
一个简单的实例:
Private Sub Form_Load()
Dim X As Long, Y As Long, bln As Boolean
bln = 取XY值("(32,33)", X, Y)
MsgBox "(32,33) X=" & X & " ,Y= " & Y
MsgBox 判断象限(X, Y)
End Sub
Public Function 取XY值(ByVal 要处理的文本 As String, ByRef X As Long, ByRef Y As Long) As Boolean
Dim A As Long, B As Long, C As Long, StrX As String, StrY As String
A = InStr(要处理的文本, "(")
B = InStr(要处理的文本, ",")
C = InStr(要处理的文本, ")")
StrX = Mid(要处理的文本, A + 1, B - A)
StrY = Mid(要处理的文本, B + 1, C - B - 1)
X = CLng(StrX)
Y = CLng(StrY)
取XY值 = True
End Function
Public Function 判断象限(X As Long, Y As Long) As String
Dim Xr As Integer, Yr As Integer
Xr = Sgn(X)
Yr = Sgn(Y)
Select Case Xr & Yr
Case "00"
判断象限 = "原点"
Case "01"
判断象限 = "Y正半轴"
Case "10"
判断象限 = "X正半轴"
Case "0-1"
判断象限 = "Y负半轴"
Case "-10"
判断象限 = "X负半轴"
Case "11"
判断象限 = "第一象限"
Case "-11"
判断象限 = "第二象限"
Case "-1-1"
判断象限 = "第三象限"
Case "1-1"
判断象限 = "第四象限"
Case Else
判断象限 = "出错了."
End Select
End Function
追问
问题是题目规定只有一个文本框
追答
Private Sub Command1_Click()
Dim strNR as String ,X As Long, Y As Long, bln As Boolean
strNR=trim(Text1.text)
bln = 取XY值(strNR, X, Y)
MsgBox strNR & " X=" & X & " ,Y= " & Y & " 象限是:" & 判断象限(X, Y)
end sub
展开全部
Option Explicit
Private Sub Command1_Click()
Dim x%, y%, r$
x = Sgn(Split(Text1, ",")(0))
y = Sgn(Split(Text1, ",")(1))
Select Case x & y
Case "00"
r = "原点"
Case "11"
r = "第一象限"
Case "-11"
r = "第二象限"
Case "-1-1"
r = "第三象限"
Case "1-1"
r = "第四象限"
End Select
MsgBox "输入点: (" & Text1.Text & ") 属于" & r
End Sub
Private Sub Command1_Click()
Dim x%, y%, r$
x = Sgn(Split(Text1, ",")(0))
y = Sgn(Split(Text1, ",")(1))
Select Case x & y
Case "00"
r = "原点"
Case "11"
r = "第一象限"
Case "-11"
r = "第二象限"
Case "-1-1"
r = "第三象限"
Case "1-1"
r = "第四象限"
End Select
MsgBox "输入点: (" & Text1.Text & ") 属于" & r
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim sst
sst=split(text1.text,",")
x=sst(0)
y=sst(1)
然后判断 X 和Y的正负喽,相信你会搞定的。。
sst=split(text1.text,",")
x=sst(0)
y=sst(1)
然后判断 X 和Y的正负喽,相信你会搞定的。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-02
展开全部
Private Sub Text1_Change()
On Error Resume Next
Dim sC, x%, y%, sInfo$
sC = Split(Trim(Text1), ",")
x = CInt(sC(0)): y = CInt(sC(1))
sInfo = IIf(x = 0 And y = 0, "原点", _
IIf(x * y = 0, IIf(x = 0, IIf(y > 0, "Y正", "Y负"), IIf(x > 0, "X正", "X负") & "半轴"), _
"第" & IIf(x * y > 0, IIf(x > 0, "一", "三"), IIf(x > 0, "四", "二")) & "象限"))
Me.Caption = sInfo
End Sub
On Error Resume Next
Dim sC, x%, y%, sInfo$
sC = Split(Trim(Text1), ",")
x = CInt(sC(0)): y = CInt(sC(1))
sInfo = IIf(x = 0 And y = 0, "原点", _
IIf(x * y = 0, IIf(x = 0, IIf(y > 0, "Y正", "Y负"), IIf(x > 0, "X正", "X负") & "半轴"), _
"第" & IIf(x * y > 0, IIf(x > 0, "一", "三"), IIf(x > 0, "四", "二")) & "象限"))
Me.Caption = sInfo
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询