Question:
Help with visual basic program?
motas
2011-06-02 05:12:37 UTC
Hi. I am making a diary program to remind me of homework that is due in (I have a terrible memory and keep getting yelled at for not handing in work). So far I have 3 forms. Menu, add (for adding tasks) and view (for viewing tasks). So far menu is done and has two buttons which go to the forms. Add is visually done but has no coding. View has nothing. Basically I have the subject, item, due date and time needed (days). First 2 are text boxes, due date is a date time picker and time needed is a numeric up down. Basically I need to save this information and then in the view form display this in the order of the next one I need to do (due date minus days required to complete). As you can tell i don't have much experience programming and only did a term of it at school. I am trying to learn this not just palm it off to someone else so please don't tell me not to just ask someone to give me code. I need to figure out how to save this information as a text file, then retrieve the information and sort it out as above.
Any help is greatly appreciated.
Thanks.
Three answers:
Bob M
2011-06-02 05:59:43 UTC
First A Note - I'm not telling you off, this really is a better way to work. In future can I ask you to change the direction of your programming, start with the data, then how you would like the data manipulated, then finally write the editor/views to match the data model as a whole.



Right, now to your sollution.



First you want your data items in a class or structure, then you need a way to arrange these in an easy to access list or array.



Your class might be something like -



(this is psudo because I don't use VB so though I know it has this functionality, I do not know off heart what the actual syntax and names are)



Public Class ProjectItem

{

public property int itemID { with get and set }

public property DateTime dateEntered { with get and set }

public property DateTime dateDue { with get and set }

public property String projectName { with get and set }

public property int hoursSpentOnProject { with get and set }

public property bool finished { with get and set }

public property string score { with get and set }

}



Then this can go into a List



Dim schoolWork As New List(Of ProjectItem)



Still before you create any forms, you now want functions to write, and select items.



The write function receives data (eventually) from the form, but you only want to write this function once and you might later want to receive the data from another source, for example from a CSV file reader, so this particular function receives its data as function parameters, set each parameter to have a default, this way your function can work out for itself which data to change in an edit, or if it is a new record. For example, if no ID is passed, then this is meant as a new record, if you have an ID and one or more other data in the parameters, then you are altering a record that exists.



Function AddOrUpdateItem(ByVal id As Integer = -1, ByVal dateentered as DateTime ... and the rest of the parameters) As Double



See if we have an ID

...Yes - then update that record with the data given, ignore those not given

...No - Then treat this an a new record, get a new ID (have a function return schoolWork.Max( n => n.itemID) + 1



End Function



Later when you write the forms you simply call the various data entry and view functions that you have already created. Remember that you can test these without any forms, making use of the console write for output (and stage data) in functions. Using a trigger to start the functions probably with dummy data, Form_load or a timer are good enough for this.



Your views have different needs, the editor just wants you to select an item then load the data for that record.



So maybe a picklist of the project names.



Your other view may want one of two (maybe three) options on viewing data, in the order of the next project due, or you might prefer in the order of least hours worked or most worked done to get the one nearest to being finished.



Dim sortedItems = From swork In schoolWork

Order By cust.dateDue



For Each item In sortedItems

Console.WriteLine(item.itemID & item.projectName

next



If you bhaven't used linq before, it is worth using because it saves you a lot of work with arrays and lists that, god forfib, you might have had to do yourself.
?
2016-12-10 13:24:44 UTC
seen common is a stunning first language because that is amazingly forgiving so a ideas as programming languages flow. In about an hour you need to be up and coming up basic calculation classes making use of VB. there are a spread of tremendous tutorials on the internet that may help you start up. purely confirm you recognize which version of VB you're making use of. The older VB6 is a lot more convenient than the more recent VB.internet 2005. There extremely arent any languages to study earlier VB because that is so basic. notwithstanding, it should be crucial language. strong success.
ratatat49
2011-06-02 05:24:29 UTC
This covers reading from text files in Visual Basic:



http://msdn.microsoft.com/en-us/library/wz100x8w%28v=vs.80%29.aspx



This covers writing to text files:



http://msdn.microsoft.com/en-us/library/wz100x8w%28v=vs.80%29.aspx


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...