1 / 12

Miscellaneous Visual Basic Questions and Answers

Miscellaneous Visual Basic Questions and Answers. Screen/Button Manipulations. Unload Form Load Form Form.Show Form.Hide ControlButton.Visible = True/False cmdNextPage.Visible = True (shows the button) cmdNextPage.Visible = False (hides the button). Subroutines/Functions.

ervin
Download Presentation

Miscellaneous Visual Basic Questions and Answers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Miscellaneous Visual Basic Questions and Answers

  2. Screen/Button Manipulations • Unload Form • Load Form • Form.Show • Form.Hide • ControlButton.Visible = True/False • cmdNextPage.Visible = True (shows the button) • cmdNextPage.Visible = False (hides the button)

  3. Subroutines/Functions • Access to variables • Form variables • Global variables • arguments passed to/from the function • Calling statement • Call functionname (arguments) • Function statement • Private Function functionname (arguments)

  4. Autonumber in ACCESS • Order number in ACCESS can be defined as autonumber • Autonumber is a “long integer” • Access will automatically increment the order number by one for each new order • Visual Basic is not so nice!

  5. How to do a query on an integer field Dim strFind as string Dim num as Integer num = val(txtOrder.text) strFind = “[Order Number] = “ & num datOrder.Recordset.FindFirst strFind If datOrder.Recordset.Nomatch then msgbox (“order number: “ & txtOrder.text & “ not on file”) End If

  6. Date Fields and Functions • lblDate.caption = Now • Now: mm-dd-yy hh:mm:ss • What if you only want part of this field • orddate = Now • lblMonth.caption = Month(orddate) • lblDay.caption = Day(orddate) • lblYear.caption = Year(orddate) • lblDate.caption = Month(orddate) & “-” & Day(orddate) & “-” Year(orddate)

  7. Another Date Method • Create a field in Access: order date • Type: Date/Time • Subtype: Short Date (mm-dd-yy) • Default: Now() • ACCESS will automatically short today’s date in the mm-dd-yy format on any records added to the ACCESS database by Visual Basic

  8. Advantages/Disadvantages • Allowing ACCESS to insert today’s date automatically • Using functions in Visual Basic to update the fields with the date

  9. How to add the next order record Dim newnum as integer Dim orddate as date datOrder.Recordset.MoveLast newnum = datOrder.Recordset.Fields (“Order Number”).value + 1 datOrder.Recordset.Addnew datOrder.Recordset.Fields (“Order Number”) = newnum datOrder.Recordset.Fields (“Customer Id”) = txtCustID.txt orddate = now ‘date mm-dd-yy and hh:mm:ss datOrder.Recordset.Fields(“Date of Order”) = Month(orddate) & “-” & Day(orddate) & “-” & Year(orddate) datOrder.Recordset.Update Omit code in brackets if default value is set in ACCESS

  10. Msgbox • MsgBox “prompt” • Default is the vbOKonly button • Same sa MsgBox (“prompt”, vbOKOnly) • MsgBox(“prompt”, VbOKOnly, “window title”) • Can display variables in the “prompt” • Msgbox (“this is a prompt ” & txtSSN.text) • MsgBox (“prompt ” & intNumber & “ the end”)

  11. Msgbox • If you want to use other buttons: • vbYesNoCancel; vbYesNo; vbRetryCancel • need to Dim Response as Integer • response = MsgBox(“prompt”, vbYesNo, “title”) • Response = 6 for Yes; 7 for no; 3 for cancel • Can combine icon and buttons: • response = MsgBox(“prompt”, vbInformation + vbYesNo, “title”) • Options for icons: • vbCritical • vbQuestion

More Related