Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB question

Posted on 1998-06-24
8
Medium Priority
?
178 Views
Last Modified: 2010-05-03
I need to transfer data from text file to Data base(Access)
My data stored in following format in text file.
18:00-19:00       0     0  0:00     0  0:00  0:00     0     0     0   The program uses Mid function to put data into the variable and then transfer into the database. For example,
xDatetime=Mid(Textline,1,2) and then !Datetime=xDtaetime
Does anybody know, how can I do it differently?
            Thank you.
0
Comment
Question by:gima
8 Comments
 

Author Comment

by:gima
ID: 1464227
Edited text of question
0
 
LVL 2

Expert Comment

by:evertd
ID: 1464228
yes,

Dim Time1 as date
Dim Time2 as date
if isdate(mid(textline,1,5)) then
    time1 = cdate(mid(textline,1,5))
end if
if isdate(mid(textline,7,5)) then
    time2 = cdate(mid(textline,7,5))
end if
 
the function isdate(date string) returns a boolean if the date can be converted to a valid date using the cdate function. CDate(date string) return the date value of the specified string.

0
 

Author Comment

by:gima
ID: 1464229
I need to try not to use MID function. How can I find specific character in the text file?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:tomook
ID: 1464230
"instr" might be the function you want.
0
 
LVL 2

Expert Comment

by:Llandr
ID: 1464231
Why not mid?
0
 
LVL 2

Expert Comment

by:peterwest
ID: 1464232
HI,

You need to use the instr function.  The sample of data you gave above shows that there are spaces between each data item - is this the case or are they delimited with tabstops??  If they are delimited with tabs then you can find the location of each tab by using instr, if not then it's going to be much more difficult to extract each data item.

Pete

0
 
LVL 2

Accepted Solution

by:
swilt earned 100 total points
ID: 1464233
This code will split the values out using Instr


Option Explicit

Private Sub Form_Load()
    Dim sBuf As String
    Dim i As Integer
    Dim x(1 To 10) As String
   
    sBuf = "18:00-19:00       0     0  0:00     0  0:00  0:00     0     0     99"
    For i = 1 To 10
         x(i) = sGetNextEntry(sBuf)
    Next i
   
    For i = 1 To 10
        MsgBox i & ", " & x(i)
    Next i
End Sub

Private Function sGetNextEntry(sInp As String) As String
    Dim p As Integer
    Dim sRet As String
   
    sInp = Trim$(sInp)
    p = InStr(sInp, " ")
    If p = 0 Then
        sRet = sInp
        sInp = ""
    Else
        sRet = Left$(sInp, p - 1)
        sInp = Mid$(sInp, p)
    End If
   
    sGetNextEntry = sRet
End Function
0
 
LVL 4

Expert Comment

by:tomook
ID: 1464234
Just a comment on swilt's sGetNextEntry function. Note that it alters the value of the string passed to it. This is not important unless you need to keep the original string. If so, pass in a copy and everything will be fine.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question