Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sounds like homework questions to me. Try here.

iConqueror commented: cheers +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Here's one way

For r As Integer = 1 To CInt(txtNumRows.Text)
    dgvMyGrid.Rows.Add(New DataGridViewRow)
Next
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

But the Ors
But the words i typed in the textbox then to overwrite therby making d code on l4liNe 4effective

I have no idea what you are saying. You didn't say in your OP what the back end database was. You'll have to pick an appropriate connection string for your version of Access. You can find it here

To use a query with values from a textbox you can creater a query string by concatenating values as in

qry = "INSERT INTO myTable (id,name) VALUES(" _
    & txtID.Text & ",'" & txtName.Text & "')"

or you can use a parameterized query.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In order to add a record to a database you have to do an INSERT. Before you do that you have to establish a connection to the database and that requires a connection string which is specific to the type of database you are trying to connect to. For example, using MS SQL as the database you might do

con.Open("Driver={SQL Server};Server=.\SQLEXPRESS;Database=mydb;" & _
         "Trusted_Connection=yes;")
con.Execute("INSERT INTO myTable (id,name) VALUES(123,'Jim')")
con.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm not up to SQL 2012 yet (I'm using 2008) but this works for me.

My table is

FileName     VARCHAR(255) (PK)
WordDoc      VARBINARY(MAX)

To get the data into the table you have to read the Word document into a Byte array as binary. When you want to recreate the document you must write it as binary. The two routines to read and write the files are

Private Function ReadWordDoc(filename As String) As Byte()

    Dim fs As New System.IO.FileStream(filename, IO.FileMode.Open)
    Dim br As New System.IO.BinaryReader(fs)

    Dim data() As Byte = br.ReadBytes(fs.Length)

    br.Close()
    fs.Close()

    Return data

End Function

Private Sub WriteWordDoc(filename As String, data As Byte())

    Dim fs As New System.IO.FileStream(filename, IO.FileMode.Create)
    Dim bw As New System.IO.BinaryWriter(fs)

    bw.Write(b)

    bw.Close()
    fs.Close()

End Sub

Note that you should add your own error checkinig as required. Although I named the routines to work with Word docs, they will work for any file type.

Here is the code to save a document to the database and to retrieve a previously saved document.

Private Sub btnStore_Click(sender As System.Object, e As System.EventArgs) Handles btnStore.Click

    Dim con As New SqlConnection("Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;")
    Dim cmd As New SqlCommand("", con)

    Dim file As String = "D:\temp\test.docx"
    Dim doc() As Byte = ReadWordDoc(file)

    cmd.CommandText = "INSERT INTO WordDocs (FileName,WordDoc) VALUES(@FILE,@DOC)"
    cmd.Parameters.AddWithValue("@FILE", file)
    cmd.Parameters.AddWithValue("@DOC ", doc)

    con.Open()
    cmd.ExecuteNonQuery()
    con.Close()

End Sub

Private Sub btnRetrieve_Click(sender As System.Object, e As System.EventArgs) Handles btnRetrieve.Click

    Dim con As New SqlConnection("Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;")
    Dim cmd As New SqlCommand("", con)

    Dim file As String = "D:\temp\test.docx"

    cmd.CommandText = …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
  1. Since I was 18 in 1972 at University
  2. Visual Basic since I retired in '08 because it is relatively straightforward but I've always had a thing for APL. Most of my programming over all has been in FORTRAN.
  3. Not really, but programming wasn't as complex back then.
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What have you got so far?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

anal retentive

adjective

(of a person) excessively orderly and fussy

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I was just being anal ;-P

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I consider google, etc. akin to phoning the operator or directory assistance as in "a phone call you make in order to make a phone call". I go to google to go somewhere else. Although I would consider google maps as a destination.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

How would the website determine if the user is in the appropriate forum? There are some posts that are general enough that they do not belong in a lower tiered forum. The forums are arranged in hierarchies. For example, you could put a post in

Hardware and Software
    Microsoft Windows
        Windows Vista and Windows 7 / 8

If you find that your post has gone into the wrong forum you can always flag the post or PM a moderator to request that it be moved.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I would not like anonymous comments. I think if you have something to say then you should be willing to have your name attached to it especially when what you have to say affects the reputation of another user. Having said that I have seen how anonymous voting can be abused. We have seen users whose posting quality has tanked because another user had gone through the forums and downvoted averything by that user. Something that could alleviate that would be to disallow multiple downvotes within a given time frame, especially against a particular user. However, this would not prevent someone from downvoting one post. I'm assuming that this arose from the regex thread in the vb.net forum. In that case the user who downvoted had three (actually four) options:

  1. downvote anonymously
  2. downvote with comment
  3. reply in-thread
  4. do nothing

The first choice gives you a hit on your posting quality whereas the second choice affects your reputation. As you saw in the thread, I chose option 3. I would have chosen option 4 had it not been for your reaction to the downvote (which I will state again that I was not responsible for). While I found your proposed solution overly complex for the problem, the OP was free to ignore it.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Perhaps something like this

'This assumes that only valid selections appear in cboSearchType

Dim sql As String = "SELECT * FROM BusinessInfo WHERE "

Select Case cboSearchType.Text

    Case "Accredited Month"
        sql = sql & AccreditationDate " & " like '" & cboMonths.Text & "%'" 
    Case "Accredited Year"
        sql = sql & AccreditationDate " & " like '" & txtSEARCH.Text & "%'" 
    Case "Applicant Name"
        sql = sql & ApplicantName " & " like '" & txtSEARCH.Text & "%'" 
    Case "Business Name"
        sql = sql & BusinessName " & " like '" & txtSEARCH.Text & "%'"  

End Select

With grdSearchResults

    .Rows = .Rows - .Rows + 1

    If rs.State = 1 Then rs.Close()
    rs.Open sql, con

    While rs.EOF = False
        .Redraw = False
        .Rows = .Rows + 1
        .Row = .Rows - 1
        .Col = 1: .Text = grdSearchResults.Rows - 1
        .Col = 2: .Text = rs!BusinessName
        .Col = 3: .Text = rs!ApplicantType
        .Col = 4: .Text = rs!ApplicantName
        .Col = 5: .Text = rs!BusinessAddress
        .Col = 6: .Text = rs!AccreditationDate
        .Redraw = True
        rs.MoveNext
    Wend

End With

Although I should point out that you might not want to keep the connection open. The preferred method is to keep connections open only as long as they are immediately needed. In that case you should do something like

If con.State <> 1 Then con.Open()

rs.Open sql, con

'the loop goes here

rs.Close()
con.Close()
Stuugie commented: Just because the OP should have, nice work. +5
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It wasn't me who downvoted but as a guess, I'd say it was an overly complex solution to a simple problem. In my opinion that didn't justify a downvote so I upvoted to cancel it.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That answer would have been more helpful if you had included the number.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

So how do we make use of tags to do a search when the Daniweb search uses Google?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't have Access installed so I can't test this but try

cmd.CommandText = "SELECT COUNT(*)" &
                  "  FROM Userr" &
                  " WHERE StrCmp([UserID],?,0) = 0" &
                  "   AND StrCmp([User Password],?,0) = 0"

cmd.Parameters.AddWithValue("@parm", txtUserName.Text)
cmd.Parameters.AddWithValue("@parm", txtUserPassWord.Text)

con.Open()

Dim numrec As Integer = cmd.ExecuteNonQuery()
MsgBox(If(numrec = 1, "match", "no match"))

con.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Interesting how the Stalin's Apology that was linked to contains a reference to Thalidomide which wasn't developed until a year after his death and for which the teratogenic effects weren't discovered until much later. That does not refute the point being made but it should at least be accurate.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Five women are murdered with a gun in the United States every day, most often by an intimate partner. From 2001 to 2012, 6,410 women were murdered in the US by an intimate partner using a gun—more than the total number of U.S. troops killed in action during the entirety of the wars in Iraq and Afghanistan combined. source

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I didn't even consider seafood ;-P

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I would suggest windows 8 because I use it and it works well and has a better user interface than windows 7

Keep in mind that this is one user's opinion and was given with no explanation as to why the interface is "better".

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

We are just going around in circles so I'll have to pass on this. Your code isn't doing what you want so reading your code to figure out what you want is pointless, and your explanation doesn't make any sense (to me) so reading the explanation doesn't help. Perhaps you can find a friend who is more fluent in English to provide a clearer explanation.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

As has been pointed out, there are too many variables to be able to answer that question. Aside from questions about quality of land, length of growing season, etc., there is the question about whether each family/group is expected to be self sustaining. I think we can discount pesticides and fertilizer. Arable land when properly maintained using crop rotation and fallowing does not require fertilizer. My grandfather was a market gardener as were all four of his sons so I have a little knowledge about this. None of them used fertilizer or pesticides. However, none of their farms could be considered self sustaining - all raised vegetables, no animals other than the horses my grandfather used for labour.

Another question is whether or not that land is to be worked by hand/animal power or by powered machines. My grandfather used machines pulled by horses. My father had a tractor and other powered machines.

I think the question does not have a simple answer, and a more complex answer that takes into account all the variables would require time and resources beyond anyone here. Having said that, I think someone with experience in agriculture and nutririon might hazard a guess as to the maximum number of people this planet could theoretically support under ideal conditions.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I was reminded today about another peeve. It's how the execs have decided to rebrand "reruns" as "encore presentations". As George Carlin said, "shoot is just shit with two ohs".

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

At least five Americans have accidentally shot off their own penises since 2010. source

RikTelner commented: At least you know it's there. It was* +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

But Americans (and Canadians) eat a lot of beef which requires much more land per pound of protein to produce than other forms of protein so that skews the numbers. Also, what is the definition of "living requirements"? Is it bare minimum to keep alive or comfortably alive? Are we talking poverty level subsistence or middle class?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm not sure I understand what you are asking but if you want to do a case sensitive selection on the database you can do

SELECT *
  FROM Userr
 WHERE [UserID] COLLATE Latin1_General_CS_AS = 'username'
   AND [User Password] COLLATE Latin1_General_CS_AS = 'password'

If you are only interested in whether the case sensitive username and password are present then just do SELECT COUNT(*) rather than SELECT *

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you think your code is working then there is no point in my looking at it. If it isn't working then I have to know what you are trying to do in order to offer suggestions. The problem is that, based on your explanation, I do not have any idea what you are trying to do. How are we supposed to make sense statements like

in which where I base of. ' It means i can base in character_count.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Yes. It was.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sorry about that. I followed the wrong link, but the problem is the same. According to the "correct" mapping, 63 maps to ab. But there is no unique inverse mapping. ab could map back to 63 or to 0, 1. You can't get back to where you started because there is no way to determine how to parse the strings. Here's an example.

124, 868, 868 = ba na na (banana)
1, 0, 13, 0, 13, 0 = b a n a n a (banana)
1, 75, 75, 0 = b an an a (banana)

The mapping is not unique.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Small correction then. Add a ByRef to

Private Sub getDaysOut(ByRef intDays As Integer)

so that the entered value of intDays is returned to the calling code. I have to say, though, that by insisting you use a Sub rather than a Function, your instructor is teaching you bad habits.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

According to spending accounts from the 2012 US elections, senators had to raise, on average, $14,351 a day for every day they were in office the previous term. That is over $5.2 million per year.

Those kinds of donations come with strings attached. In 2010, a letter opposing net neutrality was signed by 74 Democrats. A subsequent investigation showed that these Democrats got more money on average from phone and cable companies than other house members. The same situation arose again in 2014 when 20 house Democrats signed a similar letter. In at least one case, one of the signatories received more than five times as much (approximately $60,000). Marsha Blackburn is a vocal opponent of net neutrality. Three of her top five contributors are the National Cable and Telecommunications Association, AT&T and Verizon.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I use Skype frequently but almost never for video so I consider it a coonvenience rather than the devil's handiwork. I would say that 90% of the time I use it for interactive messaging and the other 10% to save on long distance charges to talk to my older son. The video never works that well anyway.

Incidentally, did anyone see episode 5 of Silicon Valley where the head of the Google clone is trying to use the latest tech to communicate with an employee? It's priceless. First he tries holography (a technology purchased for 2 billion from a startup). This fails miserably. Then he tries Skype which also cuts out followed by the same thing over cell phone. It's a great example of how often the technology fails to live up to the hype.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Who is to say how technology will impact your career. For example, I was a real-time programmer for a major electric utility (generation, transmission and distribution). You may recall a few years back when they had that cold fusion fiasco. As unlikely as it was to be real, had it been real it would likely have bankrupted my company. Even though the distribution network would still be needed, how do you pay off the massive debt incurred by building hydroelectric dams that are no longer needed? The product your company makes today could be made as obsolete as buggy whips by the most unforeseen tech change.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Interesting. Your OP was about calculating late fees yet you post an unrelated project to calculate the average of midterm and final exams. As for "using modules, not functions", that statement does not apply because you can use functions in modules.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You should be using TRY/CATCH rather than On Error. Also, because you haven't included the code for ExecSQL or the text of any error message there is no way to offer meaningful suggestions.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

According to your earlier post, 62 should translate to ba. My point is that once you have ba how do you know if it should translate back to 62 or 1 (b) and 0 (a)?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In my earlier days I maintained the software at several hydroelectric generating stations. The source and object modules were maintained on an IBM mainframe. A cross compiler was used to generate the object (link edit) modules. My superiors decided to implement a new corporate wide naming standard. The current names as defined by me were of the form

sys1.srcelib.jenpeg(module)
sys1.linklib.jenpeg(module)

"module" was a descriptive name that clearly indicated the module's function. There were other libs for other stations like kettle (Kettle Rapids), etc. The new standard would have allocated corporate mandated names for each level leaving me a maximum of four characters to distinguish between stations and modules. Effectively that would have meant creating names like j141 to replace jenpeg(analog). I explained that by implementing the new standard they would be guaranteeing confusion and the loss (due to obfuscation) of modules. They eventually saw it my way and left me to my own standard.

The reason we use names instead of numbers for file names is because names have more meaning. By not choosing descriptive names Microsoft apparently disagrees.

But that's just my opinion.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I saw the link and it eventually took me to a page with the options

ENU\x64\SqlLocalDB.msi
ENU\x86\SqlLocalDB.msi
SQLEXPR_x64_ENU.exe
SQLEXPR_x86_ENU.exe
SQLEXPR32_x86_ENU.exe
SQLEXPRADV_x64_ENU.exe

In true Microsoft fashion they still label with x86 and x64 which (IMHO) is as brain dead a naming convention now as it was originally.

x86 = 32 bit
x64 = 64 bit

WTF. So I know the difference but that does not make it logical (or sane). And once I have decided on the 32 bit version, do I choose

ENU\x86\SqlLocalDB.msi
SQLEXPR_x86_ENU.exe
SQLEXPR32_x86_ENU.exe

That was the whole point of the post. If they insist on a stupid naming convention then they should at least annotate.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You might try rewriting it as a function without the global as in

Private Function calculateFees (ByVal intDays As Integer, ByVal decFee As Decimal) As Decimal

    If intDays <= 3 Then
        return decFee
    Else
        return CDec((intDays - 3) * 1.5 + decFee)
    End If

End Function

I'm assuming decFee is defined as Decimal. In the calling code you would do

fee = calculateFees(numdays, decfee)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In true Microsoft fashion they have made the download process so counterintuitive that your chances of getting what you want is near impossible. Fortunately someone has created a "simple" 12 step process. For yuks, see also here.

And to see how little things have improved see Bill Gates Chews Out Microsoft Over Windows XP

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

“The worst illiterate is the political illiterate, he doesn’t hear, doesn’t speak, nor participates in the political events. He doesn’t know the cost of life, the price of the bean, of the fish, of the flour, of the rent, of the shoes and of the medicine, all depends on political decisions. The political illiterate is so stupid that he is proud and swells his chest saying that he hates politics. The imbecile doesn’t know that, from his political ignorance is born the prostitute, the abandoned child, and the worst thieves of all, the bad politician, corrupted and flunky of the national and multinational companies.”

Bertolt Brecht

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Political illiteracy is the manure for the flourishing of political appeals based on sheer ignorance. - CJ Werleman

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can find it here

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It will take less space than creating code for each special case. Your mapping is not reversible. For example, how will you determine if the string "aba" should be grouped as "a", "b", "a", or "a", "ba"?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Please start a new thread for this question.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You've never heard of Google?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That's not what I asked for and your explanation still does not make sense (I'll assume language diffferences). I asked for sample input and sample output but perhaps we can work with this. What you have is a straight mapping of a continuous set of integers to string. I can't see any obvious way of generating the mapping via code other than creating an array of integers and just indexing to get the resulting string. For example, if you take your list and create a file with one line per entry as in

Map.txt
=======
a
b
c
d
e
.
.
.
arM
arN
arO

then you can define

Private map() As String = = System.IO.File.ReadAllLines("map.txt")

To convert an integer to its corresponding string you just do

If num >= 0 and num <= Ubound(map) Then
    str = Map(num)
Else
    str = "?"
End If

I have no idea how this relates to

(b(a(a to 9) to 9(a to 9)) To 9(a(a to 9) to 9(a to 9))
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can replace text by setting the properties SelectionStart and SelectionLength then replacinig the selected text by assigning the replacement string to SelectedText. If you set SelectionLength to 0 then the text is inserted at the given point. For example, to insert a string at position 20, do

RichTextBox1.SelectionStart = 20
RichTextBox1.SelectionLength = 0
RichTextBox1.SelectedText = "inserted string"