Click here to Skip to main content
15,513,762 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Extracting username from a access database to show username after logging on Pin
Jeremy Haley 20226-Jan-22 6:55
Jeremy Haley 20226-Jan-22 6:55 
GeneralRe: Extracting username from a access database to show username after logging on Pin
Richard MacCutchan6-Jan-22 7:53
mveRichard MacCutchan6-Jan-22 7:53 
SuggestionRe: Extracting username from a access database to show username after logging on Pin
Richard Deeming6-Jan-22 6:57
mveRichard Deeming6-Jan-22 6:57 
Questioncombine two datatable Pin
Member 143292662-Jan-22 18:44
Member 143292662-Jan-22 18:44 
AnswerRe: combine two datatable Pin
Richard Deeming4-Jan-22 0:54
mveRichard Deeming4-Jan-22 0:54 
GeneralRe: combine two datatable Pin
Member 143292665-Jan-22 16:16
Member 143292665-Jan-22 16:16 
AnswerRe: combine two datatable Pin
Raphael Adeniji7-May-22 6:09
Raphael Adeniji7-May-22 6:09 
QuestionFind the 4th Tue of the Month when the Year changes Pin
Choroid30-Dec-21 9:41
Choroid30-Dec-21 9:41 
I have written a Check Book application and the code that calculates the 4th Tue of the Month is failing when we enter a new Year. I have added an additional Function that works but the code seems less tan elegant. I have tested a few changes with no results.
Without posting a lot of unnecessary code here is the process and the relevant code that works now.
I am storing he 4th Tue of the month in a SQLite DB and when the user writes a check I am testing if the date today is greater than the stored DB date. If this test is true than I update the stored date to the 4th Tue for next Month. I would like to know if there is a better way to design this process ?
Perhaps only using one Function.

Public Sub GetDateInfo()
    Using conn As New SQLiteConnection($"Data Source = '{gv_dbName}';Version=3;")
        conn.Open()
        Using cmd As SQLiteCommand = New SQLiteCommand($"SELECT * FROM DateInfoTable WHERE DID = '1'", conn)
            Using rdr As SQLite.SQLiteDataReader = cmd.ExecuteReader
                While rdr.Read()
                    varSearchDate = CDate(rdr("diTESTdate"))
                End While
            End Using
        End Using
    End Using
End Sub


This is the code that executes when user writes a check

Public Sub testDates()

    GetDateInfo()

    'Other Option
    'ElseIf dateToday > varSearchDate And CInt(varSearchDate.ToString.Substring(0, 2)) = 12 Then
    '============================================================================================
    Dim dateToday = Date.Today
    Dim mo As String
    mo = dateToday.ToString("MM")
    'mo = varSearchDate.ToString("MM")
    'line above for testing for NOV

    If dateToday > varSearchDate And CInt(mo) <> 12 Then
        varFTue = CDate(FourthTueOfNextMonth(Date.Today).ToString("yyyy-M-d"))
        WriteNewFourthTue()
        gvTxType = "SS Deposit"
    ElseIf dateToday > varSearchDate And CInt(mo) = 12 Then
        varFTue = CDate(FourthTueOfNewYear(Date.Today).ToString("yyyy-M-d"))
        MsgBox("varFTue " & varFTue)
        WriteNewFourthTue()
        gvTxType = "SS Deposit"
    End If

End Sub


These are the two Functions that are in a Data Module
Function FourthTueOfNextMonth(dt As Date) As Date
    Dim currDate = New Date(dt.Year, dt.Month, 1)
    Dim nTuesday As Integer

    While nTuesday < 4
        If currDate.DayOfWeek = DayOfWeek.Tuesday Then
            nTuesday += 1
        End If
        currDate = currDate.AddDays(1)
    End While

    Return New Date(dt.Year, dt.Month, currDate.Day - 1)

End Function

Function FourthTueOfNewYear(dt As Date) As Date
    Dim currDate = New Date(dt.Year + 1, dt.Month - 11, 1)
    Dim nTuesday As Integer

    While nTuesday < 4
        If currDate.DayOfWeek = DayOfWeek.Tuesday Then
            nTuesday += 1
        End If
        currDate = currDate.AddDays(1)
    End While

    Return New Date(dt.Year + 1, dt.Month - 11, currDate.Day - 1)

End Function

AnswerRe: Find the 4th Tue of the Month when the Year changes Pin
Gerry Schmitz30-Dec-21 10:37
mveGerry Schmitz30-Dec-21 10:37 
GeneralRe: Find the 4th Tue of the Month when the Year changes Pin
Choroid30-Dec-21 11:30
Choroid30-Dec-21 11:30 
AnswerRe: Find the 4th Tue of the Month when the Year changes Pin
Thava Rajan31-Dec-21 15:13
professionalThava Rajan31-Dec-21 15:13 
GeneralRe: Find the 4th Tue of the Month when the Year changes Pin
Choroid1-Jan-22 3:18
Choroid1-Jan-22 3:18 
QuestionI need help. how do i code it??? Pin
Member 1548021627-Dec-21 16:33
Member 1548021627-Dec-21 16:33 
AnswerRe: I need help. how do i code it??? Pin
Richard MacCutchan27-Dec-21 22:46
mveRichard MacCutchan27-Dec-21 22:46 
QuestionHow to display actual values on a chart using the Mouse_Move event. Pin
zomalaja25-Dec-21 14:10
zomalaja25-Dec-21 14:10 
QuestionHow to BitConverter.GetBytes() return 2 digits only Pin
EngrImad4-Dec-21 0:39
EngrImad4-Dec-21 0:39 
GeneralRe: How to BitConverter.GetBytes() return 2 digits only Pin
Richard MacCutchan4-Dec-21 1:18
mveRichard MacCutchan4-Dec-21 1:18 
AnswerRe: How to BitConverter.GetBytes() return 2 digits only Pin
EngrImad4-Dec-21 2:54
EngrImad4-Dec-21 2:54 
AnswerRe: How to BitConverter.GetBytes() return 2 digits only Pin
Dave Kreskowiak4-Dec-21 4:43
mveDave Kreskowiak4-Dec-21 4:43 
Questionerror 50003 in vb6 in win 10 Pin
Member 110192491-Dec-21 1:10
Member 110192491-Dec-21 1:10 
AnswerRe: error 50003 in vb6 in win 10 Pin
jsc421-Dec-21 1:26
professionaljsc421-Dec-21 1:26 
AnswerRe: error 50003 in vb6 in win 10 Pin
Richard Deeming1-Dec-21 2:08
mveRichard Deeming1-Dec-21 2:08 
QuestionHi How can i print listview with database im using phpmyadmin xampp Pin
Kyooshi29-Nov-21 20:54
Kyooshi29-Nov-21 20:54 
AnswerRe: Hi How can i print listview with database im using phpmyadmin xampp Pin
Richard Deeming29-Nov-21 22:47
mveRichard Deeming29-Nov-21 22:47 
AnswerRe: Hi How can i print listview with database im using phpmyadmin xampp Pin
Richard MacCutchan29-Nov-21 22:56
mveRichard MacCutchan29-Nov-21 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.