Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

very simple!!! VERY!

Hi,
easy points:
1. code for an application which on load reads from a text file in the same directory called "browser.txt".
it does this once every 20 seconds.
if the text "asdf" is retrieved from the first line, it opens default browser.
if not, it keeps on trying to read the file every 20 seconds.
no labels, no command buttons. nothing.

2. an application which on load writes to a text file called "browser.txt" the text "asdf".
again. no labels or command buttons.

asap.
thanks.
0
11ods
Asked:
11ods
  • 6
  • 4
  • 3
  • +2
1 Solution
 
QJohnsonCommented:
Reading the file is simple:

==========================================
dim nHandle as integer
dim sBuffer as string

nHandle = FreeFile
Open app.path & "\browser.txt" for input as #nHandle
Input #nHandle, sBuffer
Close #nHandle
'    now the value of the first line of text is in sBuffer
'    so do your testing
==========================================

Writing the file is simple, too.

==========================================
dim nHandle as integer
dim sBuffer as string

nHandle = FreeFile
Open app.path & "\browser.txt" for output as #nHandle
Print #nHandle, "asdf" & vbcrlf
Close #nHandle
==========================================

Now you just need to put a timer control on your form, set the interval to the desired time and put the code in its event so that it gets fired every 20 seconds.
0
 
11odsAuthor Commented:
i'm getting end of file errors

and i'm looking for full code

including how to set the timer etc..
0
 
11odsAuthor Commented:
and your app doesnt follow directions. it needs to open the default web browser once it gets "asdf"
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!

 
mlmccCommented:
Is this homework?

mlmcc
0
 
11odsAuthor Commented:
no i'm past that stage.
0
 
avya2kCommented:
Option Explicit
Dim fn As String

Private Sub Form_Load()
    fn = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & "Browser.txt"
    If (Dir(fn) = "") Then
        Open fn For Output As #1
            Print #1, "ASDF"
        Close #1
    End If
End Sub

Private Sub Timer1_Timer()
    Dim msg As String
    If (Dir(fn) = "") Then
        Open fn For Input As #1
            While Not EOF(1)
                Line Input #1, msg
                If (msg = "ASDF") Then
                    Shell "C:\program Files\Internet explorer\Iexplorer.exe", vbNormalFocus
                    Close #1
                    Exit Sub
                End If
            Wend
        Close #1
    End If
End Sub
0
 
avya2kCommented:
insert timer from ur toolbox and set its interval to 20000
0
 
QJohnsonCommented:
No one is writing an application for you here even for 1000 points.  If this isn't enough help, maybe some other gracious individual will grace you with more.

But they shouldn't in my opinion.  

This is a forum for professional developers solving real world problems with a minimum amount of self-sufficiency who come here for hints to get them pointed in the right direction for a solution.  And they are happy to run with the hint and get their work done.  They don't come here looking for someone to do their job for them.
0
 
11odsAuthor Commented:
QJohnson.

i am not some professional developer. all i wanted is a simple application. if i dont know how to check for end of file errors then sorry.
all i was looking for is for someone to make a simple application. surely enough, someone kindly did.
if you posted something very vague which didnt work its not my fault that i do not want to give you the points.

also i am not planning to learn the whole visual basic language if all i need is a very simple application. i have some points, and i needed an application.
points + someone willing to write an application = works.

its not as if i asked for you to code me a graphic design application.
"dont have a cow".

avya2k: checking the application now ...
0
 
mlmccCommented:
You are asking for 2 complete applications.  Yes they are relatively easy to write, but as professinals we try to make the code maintainable and useful.

There are numerous websites where for a price someone will write complete applications.  This one would probably cost between $25 and $100 dependinng on exactly what you required.

In that price range you would get an executable and no source code.

mlmcc
0
 
noCigarCommented:
11ods: i agree compleatly.
plus. you dont need to pay that bullshit.
here you go.

application #1: to read. all you will need to do is add a timer object.
_____________________________________________________
Option Explicit
Dim intFileNum As Integer
Dim strData As String
Dim counter As Integer
Dim R As Long

Private Sub Form_Load()
 Timer1.Interval = 1000
 Timer1.Enabled = True
 intFileNum = FreeFile
End Sub

Private Sub Timer1_Timer()
counter = counter + 1
If (counter > 1000) Then
 Timer1.Enabled = False
Else
  Open App.Path & "\browser.txt" For Input As #intFileNum
  Do While Not EOF(intFileNum)
   Line Input #intFileNum, strData
    If (strData = "asdf") Then
      R = ShellExecute(Me.hwnd, "Open", "http://www.QJohnson.com", _
      vbNullString, App.Path, vbNormalFocus)
      Close #intFileNum
      Exit Sub
    End If
  Close #intFileNum
 Loop
 Close #intFileNum
End If
End Sub
0
 
noCigarCommented:
also, for application # 1 add a module
which has the following code:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As Long, ByVal lpOperation As String, _
        ByVal lpFile As String, ByVal lpParameters As String, _
        ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

0
 
noCigarCommented:
application #2: to read the file. again insert a timer.

______________________________________________________
Private Sub Form_Load()
Timer1.Interval = 60000 'About 1 minute
Timer1.Enabled = True

Dim nHandle As Integer
Dim sBuffer As String
nHandle = FreeFile
Open App.Path & "\browser.txt" For Output As #nHandle
Print #nHandle, "asdf" & vbCrLf
Close #nHandle
End Sub



enjoy the FREE sourcecode.
0
 
11odsAuthor Commented:
excellent.

just what i was looking for.
well done.
looks like there are some professionals that dont only think about the money.

thank you for helping me.
lol at the web address you make the browser jump to :)
0
 
avya2kCommented:
11ods
may i know what was wrong in my answer just to improve myself
0
 
avya2kCommented:
sorry make 'answer' as comment
0
 
11odsAuthor Commented:
i was asking for two seperate applications.

and it didnt open default web browser for some reason...

but thanks a lot anyway. i really appriciate it.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now