| |

VerySource

 Forgot password?
 Register
Search
View: 991|Reply: 5

Ask a code

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-22 16:00:02
| Show all posts |Read mode
I have three texts. The first text is a fixed three-digit number, the second text value is the neighbor of the first text value, and the third is the remaining number between 0 and 9.
Let me give an example, if text1.text = "267" then text2.text = "13458"
text3.text = "09"
How to write this using VB?
Another problem is that the records in my database table are three digits. I want to count the number of times a certain number appears in the first ten records. How can this be achieved?
For example, the first three records are 379,290,237
   Then I want to know that the number of occurrences of 9 is twice,
Masters help, how to use code to achieve?
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-2-2 09:36:01
| Show all posts
1.
private function GetNext (byval iValue as string) as string
  dim i as byte
  dim strRet as integer
  dim j as byte

  strRet = ""
  for i = 1 to 3
     j = cbyte (mid (ivalue, i, 1))
     strRet = strRet&cstr (j-1)&cstr (j + 1)
  next
  GetNext = strRet
end function

2. Read out the first ten records first, connect them into a string, and then use the cycle to judge
objconn.open
sql = "select top 10 field from table"
objrs.open sql, objconn, 1,1
strRet = objRs.getstring (, "", "")
intCount = 0
for i = 1 to len (strRet)
   if mid (strRet, i, 1) = "9" then
      intCount = intCount +1
   end if
next
msgbox "Total"&intCount&"times"
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-2 15:27:01
| Show all posts
Your first code did not produce the result of text3, and if j is zero, and you will still have duplicate values
Don't just follow my example, think about it comprehensively,
The second code, my record is not separated by, is the record in the database table, I use the comma interval
Your loop should take each record from the record table and judge each record separately
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-2-6 22:45:02
| Show all posts
Private Sub Command1_Click ()
Dim n (3), n1, n2, a (9), i, j, s
For i = 1 To Len (Text1)
    n (i) = Mid (Text1, i, 1): a (n (i)) = 1
Next
For i = 1 To Len (Text1)
    If n (i)> 0 Then n1 = n1&IIf (a (n (i)-1) = 0 And n (i)> 0, n (i)-1, ""): a (n (i) -1) = 1
    If n (i) <9 Then n1 = n1&IIf (a (n (i) + 1) = 0 And n (i) <9, n (i) + 1, ""): a (n (i) + 1) = 1
Next
For i = 0 To 9
    n2 = n2&IIf (a (i), "", i)
Next
Text2 = n1: Text3 = n2
End Sub
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-7 12:30:01
| Show all posts
''1
Option Explicit

Private Sub Form_Load ()
  Dim m As Long, n As Long
  Dim Temp As String
  Dim Str1 As String, Str2 As String, Str3 As String
  
  Str1 = "378"
  
  For m = 1 To 3
     n = Val (Mid (Str1, m, 1))
     Temp = CStr (n-1)
     If Temp <0 Then Temp = ""
     If InStr (1, Str1, Temp) = 0 And InStr (1, Str2, Temp) = 0 Then Str2 = Str2&Temp
     
     Temp = CStr (n + 1)
     If Temp> 9 Then Temp = ""
     If InStr (1, Str1, Temp) = 0 And InStr (1, Str2, Temp) = 0 Then Str2 = Str2&Temp
  Next m
  
  For m = 0 To 9
    If InStr (1, Str1&Str2, CStr (m)) = 0 Then Str3 = Str3&CStr (m)
  Next m
  Debug.Print Str1, Str2, Str3
  
End Sub
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-7 13:45:01
| Show all posts
'''2
Option Explicit

Private Sub Form_Load ()
'' First read the first three, concatenated into a string str1
Dim str1 As String, str2 As String
Dim m As Long
str2 = Replace (str1, "9", "")
Debug.Print Len (str2)-Len (str1) ''
End Sub
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list