Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help my VB project my please!

Options
  • 22-04-2002 4:46pm
    #1
    Closed Accounts Posts: 147 ✭✭


    Hey ho,
    I'm doing this project in vb, a end of year big ass type project, just one or 2 questions:

    How do i make a label or a button or a menu button open Internet Explorer or what ever the default browser and navigate to a link???

    This might be asking a bit much but if anyone could help me out with some search code to search for the first name of a person in a database i would really appreciate it.

    Thanks.


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    the easiest way to do this is

    Private Sub Command1_Click()
    Shell "C:\Program Files\Internet Explorer\iexplore.exe " & Text1.Text
    End Sub

    as for the second part

    you want to
    1: create a connection to the database. Try search for ADO on google or support.microsoft.com
    2: Write the SQL and store in a local variable or use a stored procedure.

    I'll post the above later if you don't have any luck


  • Closed Accounts Posts: 147 ✭✭dysfunct


    Thanks amen, but i still cant get the search function going.
    Could you tell me more? :confused:


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    OK I take it this is for a college project.

    First and foremost I wouldn't presume that the path to Iexplore.exe is always going to be the same. So try and find a better way to lauch that. If you had your program do a search for a browser on installation, and log that location in a .dat file, you would be in business. Chances are the browser will reside at that location, but as users increase the number of physical disks and number of partitions this isn't always going to be true.
    Note: But in a college scenario, where lecturers/external examiners, don't actually interogate the code fully, it would do. But generally speaking, don't get in to the habbit of hard coding things like file paths etc. ;)

    On the database front, how are you connecting to the DB?. With VB if it's a simple project, you can use the lightweight DB components, that don't require the use of SQL to query a database etc. It all depends...

    Once again this is a case of "Give More Information", that way people on open forums will return answers instead of frustrating you with questions! :)

    That's my 2.54 cents

    ;-phobos-)


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by phobos

    First and foremost I wouldn't presume that the path to Iexplore.exe is always going to be the same. So try and find a better way to lauch that.

    As a thought....

    if you shell a URL (without mentioning the program) it will cause the OS to kick up the default browser to navigate to that URL.

    Alternately, if the project will allow you to use IE explicitly, have a look at the object model of IE. You can maniplate it directly - including causing an instance of it to start, and handing it a URL.

    Third option (!) may be to use the browser control which comes with VB, if you're not required to use an external browser.

    As for the DB connectivity.....as phobos said - give details, get answers :) Alternately, tell us what you've tried, and odds are someone will tell you what you've done wrong. Its often easier than just asking us to write your code for you....cause we don' wanna do that :)

    jc


  • Closed Accounts Posts: 147 ✭✭dysfunct


    This is what i have for the link:

    Shell "C:\Program Files\Plus!\Microsoft Internet\iexplore.exe " & txtHelp.Text

    where txthelp is the site, which isnt up yet.

    The database is fairly basic, the for that i have my search button on is the same form that i have my add new, delete, undo and save member buttons on.
    What i want it to be able to do is,
    the user enters a name in the search textbox, and then displays that users info in the fields that are used to add etc.

    All i have is a data control which is connected up to the database.
    And then a bunch of textboxes hooked up to the dc.

    This is what i've tried for the search button, but it doesnt like the findfirst part and gives an error of "Argument not Optional"

    Private Sub cmdSearch_Click()
    datMembersdc.Recordset.FindFirst = "'" & txtSearchName.Text & "'"
    If datMembersdc.Recordset.NoMatch = True Then
    MsgBox ("Member Not Found")
    End If

    End Sub

    Pretty flimsy code eh?


  • Advertisement
  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Shell "C:\Program Files\Plus!\Microsoft Internet\iexplore.exe " & txtHelp.Text

    That is a very bad thing to do.

    A better solution prehaps would be...

    Shell "start " & txtHelp.Text


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    That is a very bad thing to do.

    True!,

    but the best method is actually to shell("start " & websitestring);
    I wouldn't have thought of that, good one bonkey. I haven't been doing anything platform specific for a while, so shell calls to native programs like "start" wouldn't be fresh off the top of my head.

    Right, that's sorted, so we'll be hearing nothing more of that. As for the DB, tis clear you are using the lightweight components (hehe lightweight ;) [-joking-]). Just link them up to your GUI components and off she goes. Search routines are easy, just look up something like VBexplorer of VBcode.com for some examples.

    ^ = my 2.54c

    ;-phobos-)


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by dysfunct
    This is what i've tried for the search button, but it doesnt like the findfirst part and gives an error of "Argument not Optional"

    datMembersdc.Recordset.FindFirst = "'" & txtSearchName.Text & "'"
    

    You'd be getting the error cause your syntax is wrong :) A quick search on google reveals that the syntax should be something like :
    datMembersdc.Recordset.FindFirst "SomeField=SomeValue"
    

    In your case, the contents of the textbox correspond to the SomeValue. The SomeField is the name of hte field you are searching on in the table. So, you should be using something like :
    datMembersdc.Recordset.FindFirst "SomeField = '" & txtSearchName.Text & "'"
    

    I dont know what the field in your database table is called, so I've called it SomeField here. Obviously you'd need to change that.

    Note that this will probably break if txtSearchName.Text contains an apostrophe (') but I'll leave the reason and workaround for that as an exercise to the reader ;)

    jc


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Originally posted by phobos

    but the best method is actually to shell("start " & websitestring);

    semi-colons in VB? ;)


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    semi-colons in VB?

    *cough* :rolleyes:

    ;-phobos-)


  • Advertisement
  • Registered Users Posts: 707 ✭✭✭d4r3n


    SQL = "SELECT firstname, surname FROM table WHERE firstname LIKE '%" & Cstr(txtSearchName.Text) & "%'"


  • Closed Accounts Posts: 147 ✭✭dysfunct


    Thanks a million bonkey, that line of code fixed it, although im afraid to search for O'Malley :D

    The
    Shell "start" & txtHelp.Text
    wont work for me though, any idea why?

    Thanks for the help again bonkey.


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    You Wrote: Shell "start" & txtHelp.Text

    It's supposed to be: Shell "start " & txtHelp.Text

    You were probably getting some thing like "starthttp://..."
    instead of "start http://..."

    ;-phobos-)


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by dysfunct
    Thanks a million bonkey, that line of code fixed it, although im afraid to search for O'Malley :D

    Heh. It does break then?

    Basically, if you look at the string you're building as the parameter for the FindFirst you get something like :
    Somefield='someValue'
    

    Now, if someValue contains an apostrophe, look at what you get :
    Somefield='o'Malley'
    

    See the problem? The apostrophe in o'Malley will be considered to be closing the quote, which gives a syntax error.

    There are two solutions. One is to use double quotes - which would give you :
    Somefield = "o'Malley"
    

    This solves your current problem, but if you ever search for something which contains a souble-quote, then bang - it all breaks again.

    The other/better option is to "escape" the apostrophe so that it is recognised as an apostrophe, and not a string closer.

    Would you believe that the correct way to do this is to turn it into two apostrophes? Honest.

    So....you need to change your code slightly to do something like this :

    sSearchTerm = txtSearchName.Text
    datMembersdc.Recordset.FindFirst "SomeField = '" & sSearchName & "'"

    OK - now obviously this doesnt do anything different, because I left out the code which "fixes" the apostrophe. If you have a look at the line i've italicised, and have a look at what I said you need to do, and have a look at the replace function.......it should become clear.

    jc


  • Closed Accounts Posts: 147 ✭✭dysfunct


    I typed it like that aswell Phobos and still no go.
    It gives me a file not found error.

    This is exactly how it typed:

    Private Sub mnuhelpweb_Click()

    Shell "start " & txtHelpsite.Text

    End Sub

    and the txthelpsite.text contains this link.

    http://www.boards.ie/members/dysfunct/helpsite.html


Advertisement