borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (BreakPoint in VB)Next Topic (Text generation in WORD) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Newbie
Poster Message
Lokes
Level: Guest


icon Newbie  Archived to Disk

Hello,

When storing information in a Var what code do I use to Find Text?

ie- Var = "Bob"
Find Text Var
I'm not sure what code I can use.

12-04-2002 at 07:05 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Newbie  Archived to Disk

You mean:

Dim str as String

str= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

' Does P exist in string?
If InStr(1, str, "P") > 0 Then
   MsgBox "P Exists in the string."
End If

12-04-2002 at 07:19 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Lokes
Level: Guest

icon Re: Newbie  Archived to Disk

Close, but I want to use a Find Method to get locate the String in a file. Then I am going to store the variables underneath it into an array.

<B> Label</B>
<B>--------</B>
      1
      2
      3

So I want to enter Label into the inputbox, find "Label" in the file, and store "1,2,3" in an array.

12-04-2002 at 07:44 PM
| Quote Reply
Lokes
Level: Guest

icon Re: Newbie  Archived to Disk

Hey HTML doesn't work.

12-04-2002 at 07:44 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Newbie  Archived to Disk

Not the quickest way (which would be converting the file to a database - generally), but I think the following may be closer to what you're looking for:


Option Explicit

Private Sub FindStuff()
' Would require a text box named txtSearch
    Dim Free As Integer
    Dim astr() As String
    Dim tmp As String
    
    Free = FreeFile
    
    ReDim astr(0)
    
    Open "Filename.ext" For Input As Free
    
    Do
        DoEvents
        Line Input #Free, tmp
        If InStr(1, tmp, txtSearch.Text) > 0 Then
            astr(UBound(astr())) = tmp
            ReDim Preserve astr(UBound(astr()) + 1)
        End If
    Loop Until EOF(Free)
End Sub

12-04-2002 at 08:31 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Newbie  Archived to Disk

Opening the text file as a database would look like the following:

Private Sub DBFindStuff()
    Dim adc As New ADODB.Connection
    Dim ars As New ADODB.Recordset
    Dim PathtoTextFile  As String
    
    
    Set adc = New ADODB.Connection
    Set ars = New ADODB.Recordset
    
    PathtoTextFile = App.Path & "\" 'end with terminating slash
    
    adc.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & PathtoTextFile & ";" & _
          "Extended Properties=""text;HDR=YES;FMT=Delimited"""

    ars.Open "SELECT * FROM Data.txt", adc, adOpenStatic, adLockReadOnly
' NOTE: the first line in the text file will be the field names
    If Not ars.BOF And Not ars.EOF Then
        ars.Filter = "F1='P' or F2='P' or F3='P'"
        MsgBox ars.RecordCount ' number of records where filter is true
    End If
    
    If ars.State = adStateOpen Then ars.Close
    If adc.State = adStateOpen Then adc.Close
    
    Set ars = Nothing
    Set adc = Nothing
End Sub


Text File "Data.txt" contains:
F1,F2,F3
1,2,3
a,b,c
d,e,f
g,h,i
j,k,l
m,n,o
p,q,r
q,r,p
r,p,q
4,5,6
7,8,9

12-04-2002 at 08:54 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Lokes
Level: Guest

icon Re: Newbie  Archived to Disk

Thanx JL. Guess what? I work for Oracle and I don't have access to a DB. And I can't use Access becuase it's a MS product, even though we use Win2K and Excel. Make sense? Hell know and it makes my job difficult.
Thanx again for the info.

12-04-2002 at 09:10 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Newbie  Archived to Disk

You're welcome.

Visual basic does have some access controls built into it, so you do not have to have access to open or create access databases. But given your situation, you may not want to do it, even if it would greatly increase the programs performance.

12-04-2002 at 09:29 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Lokes
Level: Guest

icon Re: Newbie  Archived to Disk

Really, I did not know that. I will try them at home.
Would you recommend a Beginner switch to .NET now or not worry about it?

12-04-2002 at 09:45 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: Newbie  Archived to Disk

I'll be getting the .NET version. I'd basically say, get to know version 6, and .NET if possible. Basically depends on whether you wish to do professional programming.

If companies decide to use the .NET version, then they'll probably need people to either 1) maintain the VB6 code, or 2) convert the VB6 to .NET.

If you have the money, get the .NET. Some things are similar, so if you know the .NET, you'll still be using some VB6 stuff (but not the same way, or as easy though).


12-04-2002 at 09:54 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : Newbie
Previous Topic (BreakPoint in VB)Next Topic (Text generation in WORD) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder