Everyone,
I have been working on a program to manage our home finances. This is a program I am writing to further my knowledge of VB.NET. So far everything is going great but I am stuck at one point. I have a tabbed view setup in my main form. The tabs are Bills, Income and Summary. I am on the last tab (summary). Right now I have the bills written to a text file and the following items are separated by a |. The items placed in the file are:
Paid To | Date | Amount | Paid By | Confirmation Number | Notes
I have a ListView setup on my summary tab. The first column is to list the bills that we pay. The rest of the columns are months with a final total at the end (not worried about those yet). What I am having trouble with is searching through the text file for current year only records and listing out the Pay To in the first column of the ListView.
Here is the code that runs in the function. I calls a second function to fill the ListView column.
Try
sr = New StreamReader(MainBillsFile, True)
Dim ListBills As New List(Of String)
While (sr.Peek() > -1)
BillitmsSum = sr.ReadLine().Split("|")
Dim dateValue As Date = Date.Parse(BillitmsSum(1))
Dim DateYear As String = dateValue.Year
If DateYear = CurrentYear Then
BillitmPayTo = BillitmsSum(0)
End If
Output_On_Launch_BillSum()
End While
sr.Close()
sr.Dispose()
Catch ex As Exception
MessageBox.Show("Error Reading From File." & ex.Message)
End Try
When this runs when the program is loaded is the following.
Lets say I have 4 items in the file 2 with 2015 dates and 2 with 2014 dates. Based on what I want to show (current year 2015) I get the following
2015 item 1
2015 item 2
2015 item 2
2015 item 2
What I think is happening is the code is seeing all the items (4 total) and pulling the 2015 ones as it should but to fill up everything is is duplicating the last item to match the total items in the file of 4.
I hope this all makes sense. This is my first post here, up to this point searching has helped me greatly but I have tried a bunch of different code and they all give the same out come.
Here is the other Method:
Sub Output_On_Launch_BillSum()
Dim LVItem3 As ListViewItem = LVBillSum.Items.Add(BillitmPayTo)
End Sub
At first glance it appears you need to call Output_On_Launch_BillSum() only if the year of the bill is the current date. I'd need to see that method to be sure though.
If DateYear = CurrentYear Then
BillitmPayTo = BillitmsSum(0)
Output_On_Launch_BillSum()
End If
Related
I recently came across a document which numbers all record lines from 1 to the end of the document. I then thought the document can be created in our database in form of a report. The numbering has been used in the document for years for easy visualisation and reference.
How do I add this numbering onto the report? I have attempted to use a loop but then I get a repeat of numbering associated with the last record only.
Private Sub Report_Activate()
Dim Counter As Integer
Dim Total As Integer
Total = 0
For Counter = 1 To 10
Total = Counter + 1
Me.txtLine.Value = Counter
'Debug.Print Counter
Next Counter
End Sub
Current Attempt:
Expected: NB Sorting on Description is not important
Use textbox RunningSum property. It is only available on report, not form. No VBA needed. Set ControlSource to: =1. Then RunningSum property to OverAll or OverGroup.
Calculating sequential identifier or any running sum in query or with code gets rather complicated in Access. It is a common topic in many forums.
So I have a combobox which gets its value in a database, at first I only need the last value inside the combobx in which i used
Dim lastitem As Integer = 0
lastitem = ClassInfo.ComboBox1.Items.Count
ClassInfo.ComboBox1.SelectedIndex = lastitem - 1
Btw I'm creating an enrollment system in which the system will automatically detects the previous year for the new enrollees to be added in the the current year, since every year is changing i need to know how to do this. Thanks for the help.
Essentially this includes 3 components.
First is a form, here the user, via a listbox, chooses multiple names.
For example, they highlight the following names.
Jane
John
Bob
They click a button called "btnGenerate" and these three names get entered as seperate records into a table called "NameCriteria" like this:
ID Name
1 Jane
2 John
3 Bob
Along with this, on-click of the button btnGenerate, a report is generated.
What I cannot seem to get working is that on the report, I hope to get a summary of what was selected on the form. I have a textbox on this report which I am trying to get to generate the following result
Jane, John, Bob
OR if there is only one name highlighted when the btnGenerate is clicked, the textbox will only display
Jane
I cannot seem to get this working. In the report, on the textbox, under the textbox's data/control source, I have entered the following code.
=[Forms]![Report]![lstName]
This just leaves the textbox blank. I have also tried referencing the table "NameCriteria" using
=[Table]![NameCriteria]![Name]
and I return #Error in the textbox.
I'd use something along these lines, using ADO, but its been a long day, so there may be simpler solution.
Public Function CONCAT_SQL(strSQL As String) As String
Dim r As ADODB.Recordset
Dim a As Variant
Set r = New ADODB.Recordset
r.Open strSQL, CurrentProject.Connection, 1
a = Split(r.GetString, Chr(13))
ReDim Preserve a(UBound(a) - 1)
CONCAT_SQL = Join(a, ",")
End Function
Called like so,
me.textbox1.value = CONCAT_SQL("Select [Name] from [NameCriteria]")
I am still learning basic programming, literally off Visual Basic 2012 v11.
Here is what I am stumped on:
I made a stupid-simple Table-Top Role-Playing Character Log application.
I made a simple dice roller/"random number" procedure and set it to fill a ListBox with each button click of "ROLL" until the max of 6 was reached. That worked fine.
However, I changed my app to link with a database to store simple character information for all of the people playing,etc. Which means I now have separate dataset TextBoxes for each click of "ROLL". Would someone please advise me on the best way to populate one TextBox per button click with a maximum of 6 clicks, please?
I was using a loop to fill the ListBox with exactly 6 entries, and started that line of thought for filling the TextBoxes, but my late-night tired brain cannot find a way to fill ONE box EACH TIME instead of all boxes every single time.
THANK YOU FOR YOUR HELP!
My Code:
Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
'Roll a character stat up to 6 and add it to the lisbox
'D20 is standard die, but stats below 6 are forgiven for this campagin
Dim Dice As New Random
Dim DiceRoll As Integer = Dice.Next(6, 20)
Dim intCount As Integer = 0
Dim Stat As String = Convert.ToString(DiceRoll)
Do While intCount < 7
Loop
End Sub
I don't believe you've included enough information to give an informed answer.
From my understanding, you'd like to take the result of the roll, and input it into one of several textboxes (you haven't given a number of textboxes, but you'd like it done in less than 6 clicks).
Depending on what the different fields will be, you may want to include your calculations within the loop, along with this, to specify the output and then roll again X times within the loop:
Do While intcount < 7
Select Case intcount
Case 1
txtBox1 = stat
Case 2
txtBox2 = stat
Case 3
txtBox3 = stat
Case 4
txtBox4 = stat
Case 5
txtBox5 = stat
Case 6
txtBox6 = stat
Case Else
'Nothing if not specified with other arguments.
'Roll again
stat = Convert.ToString(Dice.Next(6,20))
Loop
Long story short:
I need the inverted function of WeekdayName(), in the following terms:
You provide a week day name (e.g. Sunday)
You get the correspondent week day number (that depends which is the first week day as returned in WeekdayName, e.g., you get 1 for Sunday if Sunday is the first day of the week)
Background:
I'm using date functions in vb.net. So far so good. I'm using the function WeekdayName() in order to set the titles for tab pages in a TabControl. My custom control (kind of calendar control) holds the mentioned TabControl and it has the option of choosing which day of the week you want to diplay.
If you want to display ALL days, the TabControl will have TabPages filled by iterating upon the WeekdayName() function mentioned above (localized and managed by the system calendar and capitalized by me).
If you set only Tuesday and Friday, you will have two tab pages with those titles and sorted as [Tuesday | Friday]. If you decide to add Wednesday, now you should have 3 tab pages: [Tuesday | Wednesday | Friday], and so on...
In order to keep tabs sorted, when I need to insert a tab to be shown I want to provide the tab's title to check against the new-to-insert weekday name and in that way have the order resolved.
I believe one workaround is to create a fake date object with the tab's title string in it in order to have a, for instance, "Sunday" date and then use: Weekday() but I was hoping an API solution.
NOTE: This is not: how to get the day number from a date.
EDIT:
As we disscused with #jmshapland, a custom code approach using the default localization and system settings could be:
Function WeekdayNumber(day as String)
' The following initialization does not necessary go in this function.
' The idea is to have a mapping between key day name and index in the
' same order as the WeekdayName() method with the default system settings
Dim weekdayNamesCollection as Collection = New Collection()
For i = 1 to WEEKDAYS
Dim wDay as String = WeekdayName(i)
' add the day with a key with the same name
weekdayNamesCollection.add(wDay, wDay)
Next i
If weekdayNamesCollection.ContainsKey(day) Then
Return weekdayNamesCollection.IndexOfKey(day) + 1
End If
' Raise an error as the string 'day' is not in the collection
End Sub
I didn't test this out as I am in a computer without any framework and/or IDE. But basically, the idea is to return the index where the weekday name is stored in the collection (previously, it was stored in the system settings order as WeekdayName().
I don't think there's a built-in function for it. But if you are using WeekdayName then you should use it for your purpose.
Public Function WeekDayNumber(ByVal weekName As String) As Integer
Dim weekNames As New Dictionary(Of String, Integer)
For i As Integer = 1 To 7
weekNames.Add(WeekdayName(i), i)
Next
Return weekNames(weekName)
End Function
Sorry if this is formatted poorly, I never work with VB usually just C#. However, this should do what you are looking for... If you want the first day of the week to return as 0 instead of 1 just remove the + 1 from the return statement.
Private Function FindDayOfWeek(day As String) As Integer
Dim daysOfWeek = CultureInfo.CurrentCulture.DateTimeFormat.DayNames
Dim counter As Integer = Array.IndexOf(daysOfWeek, WeekdayName(1))
Dim numericDay As Integer
For i As Integer = 0 To 6
If counter > 6 Then
counter = 0
End If
If daysOfWeek(counter) = day Then
numericDay = i
Exit For
End If
counter += 1
Next
Return numericDay + 1
End Function
By using val() function, will give Day of Week number from 0 to 6 :
intDayofWeek = val(System.DateTime.Now.DayOfWeek)