Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 18th, 2008, 09:22 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default Trouble Using For Next Statement

Hi, I am returning records from my database as follows:

3 Elementary Teaching Learning Behavior Spe*****t I
3 Elementary Teaching Learning Behavior Spe*****t I-Supervising
3 Elementary Teaching Learning Disabilities
3 Elementary Teaching Mental Retardation
4 Early Childhood Teaching Self Contained General Education Age 0 - Grade 3
9 Secondary Teaching Learning Behavior Spe*****t I
9 Secondary Teaching Learning Behavior Spe*****t I-Supervising
9 Secondary Teaching Learning Disabilities
9 Secondary Teaching Mental Retardation

What I want is the following:
3 Elementary Teaching
Learning Behavior Spe*****t I
Learning Behavior Spe*****t I-Supervising
Learning Disabilities
Mental Retardation

4 Early Childhood Teaching
Self Contained General Education Age 0 - Grade 3

9 Secondary Teaching
Learning Behavior Spe*****t I
Learning Behavior Spe*****t I-Supervising
Learning Disabilities
Mental Retardation

Where 3,4 and 9 are the cert codes; Elementary Teaching, Early Childhood Teaching and Secondary Teaching are the cert desc; Learning Behavior Spe*****t I, Learning Behavior Spe*****t I-Supervising, Mental Retardation, etc are the endrs desc.

My code is not returning the desired results. Here is the code:
  If p_intRecords > 0 Then
      For p_intCount = 0 To p_dsData.Tables(0).Rows.Count - 1
        If String.IsNullOrEmpty(p_dsData.Tables(0).Rows(p_int Count).Item("cert_renew_fy").ToString) Then
                    strRenewYr = " Not Registered"
                    Else
                    strRenewYr = "06/30/" & CStr(CInt(p_dsData.Tables(0).Rows(p_intCount).Item ("cert_renew_fy")) - 1)
                    End If
                    p_strCerts &= "Cert Code:" & CStr(p_dsData.Tables(0).Rows(p_intCount).Item("cer t_code")) & ", "
                    p_strCerts &= CStr(p_dsData.Tables(0).Rows(p_intCount).Item("cer t_desc"))
                    p_strCerts &= ControlChars.CrLf

For p_intCountEndrs = 0 To p_dsData.Tables(0).Rows.Count - 1
    p_strEndrs &= "Endrs:" & CStr(p_dsData.Tables(0).Rows(p_intCount).Item("end rs_desc")) & ", "
                    Next

          p_strCombo = p_strCerts & p_strEndrs
          p_strCombo &= ControlChars.CrLf

          Next

Any ideas as to what I am doing wrong? Your help is greatly appreciated! Thanks

SLBIBS
__________________
SLBIBS
  #2 (permalink)  
Old September 18th, 2008, 09:48 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Looks like the second for next should not read the row count.. maybe another thing?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #3 (permalink)  
Old September 18th, 2008, 11:10 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Actually, the code that returns the following:

3 Elementary Teaching Learning Behavior Spe*****t I
3 Elementary Teaching Learning Behavior Spe*****t I-Supervising
3 Elementary Teaching Learning Disabilities
3 Elementary Teaching Mental Retardation
4 Early Childhood Teaching Self Contained General Education Age 0 - Grade 3
9 Secondary Teaching Learning Behavior Spe*****t I
9 Secondary Teaching Learning Behavior Spe*****t I-Supervising
9 Secondary Teaching Learning Disabilities
9 Secondary Teaching Mental Retardation

is the following code:
   If p_intRecords > 0 Then
      For p_intCount = 0 To p_dsData.Tables(0).Rows.Count - 1
         If String.IsNullOrEmpty(p_dsData.Tables(0).Rows(p_int Count).Item("cert_renew_fy").ToString) Then
                    strRenewYr = " Not Registered"
                    Else
                    strRenewYr = "06/30/" & CStr(CInt(p_dsData.Tables(0).Rows(p_intCount).Item ("cert_renew_fy")) - 1)
                    End If
                    p_strCerts &= "Cert Code:" & CStr(p_dsData.Tables(0).Rows(p_intCount).Item("cer t_code")) & ", "
                    p_strCerts &= CStr(p_dsData.Tables(0).Rows(p_intCount).Item("cer t_desc")) & ", "
                    p_strCerts &= "Endrs:" & CStr(p_dsData.Tables(0).Rows(p_intCount).Item("end rs_desc")) & ", "
          If CStr(p_dsData.Tables(0).Rows(p_intCount).Item("end rs_grd_lvl").ToString.Trim) <> vbNullString Then
                        p_strCerts &= "Endrs Grade Lvl:" & CStr(p_dsData.Tables(0).Rows(p_intCount).Item("end rs_grd_lvl")) & ", "
          End If

        p_strCerts &= "Registered Through: " & strRenewYr
        p_strCerts &= ControlChars.CrLf
      Next

I added the additional FOR NEXT in an attempt to return ONLY the Endrs Desc for the Cert Code in the intial FOR statement.

SLBIBS
  #4 (permalink)  
Old September 18th, 2008, 11:17 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Did you trace your code?? this can be easily fixed tracing the error..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #5 (permalink)  
Old September 18th, 2008, 04:27 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Not sure why you are surprised that the names aren't "grouped". You have no code whatsoever in there that even attempts to group them.

I'm not sure this is what you want, but see if it gets you closer:
Code:
If p_intRecords > 0 Then
    Dim curTable As DataTable = p_dsData.Tables(0)
    Dim curCertCode As String = ""
    For p_intCount = 0 To curTable.Rows.Count - 1
        Dim curRow As DataRow = curTable.Rows(p_intCount)
        Dim certCode As String = CStr(curRow.Item("cert_code"))
        If curCertCode <> certCode Then
            ' when cert_code changes, then and only then add a row for the cert code:
            curCertCode = certCode
            p_strCerts &= "Cert Code:" & curCertCode & ",  " _
                        & CStr(curRow.Item("cert_desc")) & ControlChars.CrLf
        End If
        Dim strRenewYear As String = curRow.Item("cert_renew_fy").ToString
        If String.IsNullOrEmpty(strRenewYear) Then
            strRenewYr = " Not Registered"
        Else
            strRenewYr = "06/30/" & CStr( CInt(strRenewYear)-1 )
        End If
        p_strCerts &= "Endrs:" & CStr(curRow.Item("endrs_desc")) & ",  "
        Dim grdLvl As String = curRow.Item("endrs_grd_lvl").ToString.Trim
        If grdLvl <> vbNullString Then p_strCerts &= "Endrs Grade Lvl:" & grdLvl & ",  "
        p_strCerts &= "Registered Through: " & strRenewYr
        p_strCerts &= ControlChars.CrLf
    Next
End If
Notice how I have used intermediate variables to shorten the code and, not so incidentally, make it run faster.
  #6 (permalink)  
Old September 18th, 2008, 05:03 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Some minor improvements (and a correction) to that code:

Code:
If p_intRecords > 0 Then
    Dim curTable As DataTable = p_dsData.Tables(0)
    Dim curCertCode As String = ""
    For Each curRow As DataRow in curTable.Rows
        Dim certCode As String = CStr(curRow.Item("cert_code"))
        If curCertCode <> certCode Then
            ' when cert_code changes, then and only then add a row for the cert code:
            curCertCode = certCode
            p_strCerts &= "Cert Code:" & curCertCode & ",  " _
                        & CStr(curRow.Item("cert_desc")) & ControlChars.CrLf
        End If

        ' notice how we put responsibility of the comma 
        ' onto the *following* data, not the preceding:
        p_strCerts &= "Endrs:" & CStr(curRow.Item("endrs_desc")) 
        Dim grdLvl As String = curRow.Item("endrs_grd_lvl").ToString.Trim
        If grdLvl <> vbNullString Then p_strCerts &= ", Endrs Grade Lvl:" & grdLvl 

        ' not best way to do all this, but at least better now
        Dim strRenew As String = curRow.Item("cert_renew_fy").ToString
        If String.IsNullOrEmpty(strRenew) Then
            strRenew = ", Not Registered"
        Else
            strRenew = ", Registered through 06/30/" & CStr( CInt(strRenew)-1 )
        End If
        p_strCerts &= strRenew & ControlChars.CrLf
    Next
End If
  #7 (permalink)  
Old September 18th, 2008, 05:09 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Is anybody besides me amused that
    S p e c i a l i s t
is displayed here as
    Spe*****t
???

And of course that is because it contains the letters "c i a l i s" which *OF COURSE* constitute spam.

The other day, I saw
    M o u s e X
turned into
    Mou****

Come on forum admins! If people are registered, don't apply ticky-tacky stupid filters like that! If the abuse posting priveleges, block them from posting and delete their posts. But don't turn good code into meaningless hash.
  #8 (permalink)  
Old September 18th, 2008, 05:53 PM
jminatel's Avatar
Wrox Staff
Points: 18,895, Level: 59
Points: 18,895, Level: 59 Points: 18,895, Level: 59 Points: 18,895, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 1,944
Thanks: 72
Thanked 139 Times in 101 Posts
Default

Hi Old Pedant. Let's continue the character substitution and spam discussion over here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=74085

Jim Minatel
Acquisitions Director
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Wrox online library: http://wrox.books24x7.com
  #9 (permalink)  
Old September 19th, 2008, 08:40 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Old Pendant, your code seems to work great (although I am throwing an error in debug mode in another block of code now)!! With your code and in Debug mode, I saw what I was looking for. I really appreciate your help (and the input from others) in getting me over the hump!!



SLBIBS
  #10 (permalink)  
Old September 19th, 2008, 09:44 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Old Pedant (sorry for the last post where I misspelled your moniker) the code works PERFECT!!

SLBIBS
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with simple JOIN statement zoltac007 SQL Server ASP 1 May 31st, 2007 10:09 AM
Trouble with IF statement jazzcatone Classic ASP Basics 1 October 19th, 2005 04:43 AM
Trouble executing SQL statement turbo_rabbit ASP.NET 1.0 and 1.1 Basics 13 July 6th, 2005 01:31 PM
Trouble with SQL statement jsanders ASP.NET 1.0 and 1.1 Basics 1 May 24th, 2005 03:11 PM
Trouble with mysql statement cbright JSP Basics 1 October 2nd, 2003 06:22 AM



All times are GMT -4. The time now is 03:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.