Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,618 members, 7,809,267 topics. Date: Friday, 26 April 2024 at 07:03 AM |
Nairaland Forum / Science/Technology / Programming / Vb.Net Tips and Tricks (2060 Views)
I Need A Help To Write A Simple Login Form Using Vb.net / Vb.net Crystal Report & Dataset / Post Ur Vb 6.0 Questions Here (2) (3) (4)
Vb.Net Tips and Tricks by hoodboi(m): 7:31pm On Jun 21, 2013 |
I was using code igniter the other day and i decided to use the ion auth as my authentication library. If you are familiar with Ion auth you would know that when registering a new user, all the library asks from you are some basic details like name, username and password. Everything else is passed in using an associative array. The library then does the job of creating the insert statement by looking at the data types of each passed value in the database and then saving appropriately. I am working on a vb.net project right now and i wrote a user class. I wanted to implement thesame thing like Ion auth in my program. I came about a solution and i wish to share it with you all 'Functin to save user details Public Function Save_User(ByVal otherString As SortedDictionary(Of String, String), ByVal otherInteger As SortedDictionary(Of String, Integer)) _ As Boolean sql = "INSERT INTO user(Id_Number,Fnam,Sex,Phon,Dob,rel,addr,cou,sta,ema" 'Join string fields to the sql statement For Each item As KeyValuePair(Of String, String) In otherString sql += "," & item.Key Next 'Join integer fields to sql statement For Each item As KeyValuePair(Of String, Integer) In otherInteger sql += "," & item.Key Next 'Join values to sql statement sql += ",utype) VALUES ('" & IdKey & "','" & FName & "','" & Sex & "'," & Phone & _ ",'" & Dob & "','" & Religion & "','" & Address & "','" & Country & "','" & State & "','" & Email For Each item As KeyValuePair(Of String, String) In otherString sql += "','" & item.Value Next 'Closing quote for last string value sql += "'" For Each item As KeyValuePair(Of String, Integer) In otherInteger sql += "," & item.Value Next sql += "," & UserType & ")" If (Gen_Object.ExecuteData(sql)) Then Return True Else Return False End If End Function The function starts with some very basic things just like ion auth. If you study the function well, what i did is that i collected two sortedDictionary Lists, one carrying string values, while the other carries integer values. I then concatenated them to the sql string using a foreach loop. After that i concatenated the variable also to the values in the sorted list. I started with the strings first and the integers next. Please note that the basic values have been supplied to their respective properties. Below is a test, passing in sortedDictionaries Dim strVal As New SortedDictionary(Of String, String) Dim intVal As New SortedDictionary(Of String, Integer) strVal.Add("marital status", "single") intVal.Add("Age", "18") Dim uu As New User MsgBox(uu.Save_User(strVal, intVal)) |
Re: Vb.Net Tips and Tricks by hoodboi(m): 9:32pm On Jun 25, 2013 |
I am currently working on a large project and i am the only one working on it. I can't afford to waste time, by writing bulky and excess code, so i always try to simplify as much as possible. Straight to the point then Tip 2: Have you ever tried to validate a really large form. I am currently working on a form that contains 33 fields and counting (These customers can come with more lists at any time). So i thought of a really short way to do things and i came up with what i would call a rather brilliant one. I will just give a simple example, you can figure out how to include some other things on your own. STEP 1) RENAME all controls you wish to validate like this e.g for fields that must contain only strings, give it Str_controlName, for int only fields name it Int_controlName etc. STEP 2) Create functions to check if a control contains any numbers, letters or any other character you do not want e.g function checkForNumbers(byval cnt as control) dim cntValue as string = cnt.text for i as integer = 0 to cntValue.lenght -1 if isNumeric(cntValue.elementAt(i) Then return True Exit For End if Next return false End Function To check for letters just use Not isNumeric and to check for non-alphanumeric characters, use Not char.IsLetterOrDigit(cntValue.elementAt(i)) STEP 3) Assuming you placed all controls on a windows form and you are validating Textboxes, use this to iterate through all controls on the form and validate. For Each cnt As Control In tb.Controls value = cnt.Name If TypeOf cnt Is TextBox And value.Substring(0, value.IndexOf("_" - 1) = "Str" Then If checkForNumber(cnt) Then cnt.BackColor = Color.LightGreen Return True End If End If Next STEP 4) Call your validate functions and pass in the control object like this checkForNumbers(controlName e.g TextBox1) |
Re: Vb.Net Tips and Tricks by Mosh1988(m): 4:59pm On Jul 01, 2013 |
Q BASIC......guy this is great program bor i try to connect my SQL Data to visual studio can u help me out? |
Re: Vb.Net Tips and Tricks by Immanuelar(m): 6:05am On Jul 02, 2013 |
please is visual basic 10 the same as vb. net |
Re: Vb.Net Tips and Tricks by hoodboi(m): 12:48pm On Jul 02, 2013 |
Mosh1988: Q BASIC......guy this is great program bor i try to connect my SQL Data to visual studio can u help me out? first of all this is not qbasic, it is vb.net...Secondly are you trying to connect through code or do you want to connect through your designer. Thirdly, i also need to see what you have done and what error you are getting. Immanuelar: please is visual basic 10 the same as vb. net Yes it is, the language is called vb.net |
Re: Vb.Net Tips and Tricks by adebayosun02: 11:26pm On Aug 23, 2013 |
hoodboi: Good day please great programmer Am a beginner on Vb 2010, please can you help me with a code to use in counting the number of numeric value between between two numeric variables using vb |
Re: Vb.Net Tips and Tricks by hoodboi(m): 11:41am On Sep 06, 2013 |
Dim value_a, value_b as integer Dim count as integer = 0 value_a = txtfirst.text Value_b = txtsecond.text For I = value_a + 1 to value_b - 1 Count += 1 Next I Lblanswer.text = count I am assuming txtfirst and txtsecond hold the first and last values. I am also assuming lblanswer holds the final answer |
(1) (Reply)
Tech Training In Ikota, Lekki , Lagos State, Techtutorsng / Caeser Cipher / Get NORD VPN Premium
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19 |