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.
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.
I'm using the BaselineWork1 timescaledata to contain a time phased calculation of resource work on individual tasks that I perform on a weekly basis. I want to zero out the previous week's calculation before I populate it with this week's calculation. Short of creating a loop to write zeros to the timescale data for each resource on each task is there a way to do this more efficiently? Could I make the beginning date and end date equal to the project's start and end date and time scale = seconds and the value to write equal to zero? For instance:
For lngCnt1 = 1 To tskCounter.Resources.Count
tskCounter.Assignments.Item(lngCnt1).TimeScaleData(StartDate:=ActiveProject.ProjectStart, EndDate:=ActiveProject.ProjectFinish, _
Type:=pjAssignmentTimescaledBaseline1Work, _
timescalunit:=pjTimescaleMinutes, Count:=1).Item(1).Value = 0
Next lngCnt1
This doesn't seem to work as it only zeros out the baseline1 work field for the date corresponding to the project start date.
To clear time-scaled work from anything but the forecast work field, you do need to loop through every assignment on every task. However, when it comes to the individual time-scale values, you can lump these together by year to reduce the iterations required.
Sub ClearBaseline1Work()
Dim projStart As Date
Dim projEnd As Date
projStart = ActiveProject.ProjectStart
projEnd = ActiveProject.ProjectFinish
Dim tsk As Task
For Each tsk In ActiveProject.Tasks
Dim asn As Assignment
For Each asn In tsk.Assignments
Dim TSValues As TimeScaleValues
Set TSValues = asn.TimeScaleData(projStart, projEnd, pjAssignmentTimescaledBaseline1Work, pjTimescaleYears)
Dim tsv As TimeScaleValue
For Each tsv In TSValues
tsv.Clear
Next tsv
asn.Baseline1Work = 0
Next asn
tsk.Baseline1Work = 0
Next tsk
End Sub
Remember that Baseline1 work values are not automatically updated at the assignment or task level; those values need to be explicitly cleared.
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)
I am developing a program for a chain of restaurants, they should normally be able to calculate their guestcount and sales through a vb.net application with a connection to dbf files.
My dataset gets filled in correctly as is my datatable (checked by filling in datarowview = right data)
But then I get a problem, in all my functions using my datatable, the datatable skips the final value, in this case it is all values from a month so it either skips 31 or day 30.
Tried while, Tried for each, debugged alot (how i found it was the last value). But now I have no idea why the last value isn't used by the function
Public Function Getgctakeout(ByVal i_table As DataTable)
table = i_table
i = 0
gctakeout = 0
For Each row As DataRow In i_table.Rows
gctakeout = gctakeout + Convert.ToDouble(row(4))
Next row
'MessageBox.Show(gctakeout)
Return gctakeout
End Function
This function does not use the value of the last row to calculate gctakeout
what in the name of the lord is wrong :)
Assuming that your DataTable is really filled correctly, you have two other options to get the sum.
Use the old DataTable.Compute method which works also with .NET < 2.0
Use Linq-To-DatSet and it's Enumerable.Sum
1)
Dim Sum = CType(table.Compute("Sum(ColumnName)", Nothing), Double)
2)
Dim Sum = table.AsEnumerable().
Sum(Function(row)row.Field(Of Double)("ColumnName"))
I am currently using DevExpress 10.2 within Visual Studio 2010. In a previous question I was trying to print the current user view of a DevExpress GridControl with the user's choice of expanded or collapsed master rows and/or group sections. I was told this was not possible at this time. I have now decided to use the following code:
gvPOinvoiceBanded.OptionsPrint.ExpandAllGroups = False
gvPOinvoiceBanded.OptionsPrint.ExpandAllDetails = False
when I want it to be completely collapsed while printing as by default these are set to true.
I was just wondering if there is someway to check either the total number of expanded master rows or the total number of collapsed master rows. I would also like to do the same thing for the groups as you can have the groups expanded while the master rows are not.
You can get the number of expanded group rows using a loop like this:
Dim ExpandedGroupCount As Integer = 0
Dim Handle As Integer = -1 'group rows have negative row handles
Do Until GridView1.GetRow(Handle) Is Nothing
If GridView1.GetRowExpanded(Handle) Then
ExpandedGroupCount += 1
End If
Handle -= 1
Loop
'Do whatever with expanded group count
MsgBox(String.Format("Number of Expanded Group Rows: {0}{2}Number of Group Rows: {1}",
ExpandedGroupCount, Math.Abs(Handle + 1), Environment.NewLine))
Similarly, you can do this to get the count of expanded master rows:
Handle = 0
Dim ExpandedMasterRowCount As Integer = 0
Do Until GridView1.GetRow(Handle) Is Nothing
If GridView1.IsMasterRow(Handle) Then
If GridView1.GetMasterRowExpanded(Handle) Then
ExpandedMasterRowCount += 1
End If
End If
Handle += 1
Loop
MsgBox(String.Format("Number of Expanded Master Rows: {0}", ExpandedMasterRowCount))
Of course, if you are only checking so that you can see if you need to set the collapse this probably isn't worth the effort. There is no direct property that provides the counts you are looking for.
You could also probably use the events that fire when rows are collapsed and expanded to track the count as it changes. You have to be careful with that though because the event only fires once when expand or collapse all happens. So if you go with that method be sure to check the rowHandle in the event arguments parameter for GridControl.InvalidRowHandle. That is the value used in the case of collapse or expand all.