Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2004, 11:31 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default Functions and variables

Hi,

Can someone please help?

I have 2 functions. The one function called CheckImg receives a variable with a value such as img=imgpath.
The other function called Update calls the CheckImg function such as:
<code>
Function Update()
Sub Update()

        CheckImg()
        Dim strUpdate As String = "update ybay_mdb...CATS T1 LEFT JOIN CATS T2 ON T1.CAT_ID=T2.CAT_ID SET CAT_NAME=@cat_name, CAT_IMAGE=@cat_image, cat_type=@cat_type WHERE T2.CAT_ID=@CAT_ID"
        Dim CMD As New SqlCommand(strUpdate, oConn)
        CMD.Parameters.Add("@cat_name", txtName.Text.Trim)
        CMD.Parameters.Add("@cat_image", img)
        CMD.Parameters.Add("@cat_type", drpType.SelectedValue)

        oConn.Open()
        CMD.ExecuteNonQuery()
        oConn.Close()
    End Sub
end Function
</code>

However, when i debug Update i see that img is nothing although in checkimg it does receive the correct value. How can i make the img in Checkimg also available in Update?

Thanks in advance.

 
Old February 4th, 2004, 02:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi,

Are you putting a subroutine inside a function? This will generate errors. If this isn't the case, then are you returning anything from the CheckImg Function?

J
 
Old February 5th, 2004, 02:27 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI,

Thanks for the reply. I made a few mistakes i see with my posting.
By mistake i added sub update.

Here is my code:
cat_id i get from the querystring.
<code>
  Sub Update()

        CheckImg()
        Dim strUpdate As String = "update ybay_mdb...CATS T1 LEFT JOIN CATS T2 ON T1.CAT_ID=T2.CAT_ID SET CAT_NAME=@cat_name, CAT_IMAGE=@cat_image, cat_type=@cat_type WHERE T2.CAT_ID=@CAT_ID"
        Dim CMD As New SqlCommand(strUpdate, oConn)
        CMD.Parameters.Add("@cat_name", txtName.Text.Trim)
        CMD.Parameters.Add("@cat_image", img)
        CMD.Parameters.Add("@cat_type", drpType.SelectedValue)

        oConn.Open()
        CMD.ExecuteNonQuery()
        oConn.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Request.QueryString("cat_id") <> "" Then
            Update()
        Else
            NewCat()
        End If

    End Sub
    Sub CheckImg()

        Dim myExt As String = Path.GetExtension(filMyFile.PostedFile.FileName)
        If (filMyFile.PostedFile.FileName <> "") Then
            Dim imgName As String = Path.GetFileNameWithoutExtension(filMyFile.PostedF ile.FileName)

            Dim imgExt As String = myExt

            img = imgName + imgExt
            If (filMyFile.PostedFile.ContentLength > maxfilelen * 1024) Then
                Response.Write("úîåðä âãåìä îãé")
                Exit Sub
            Else
                If myExt.ToLower <> ".gif" And myExt.ToLower <> ".jpg" And myExt.ToLower <> ".jpeg" And myExt.ToLower <> ".bmp" And myExt.ToLower <> ".html" And myExt.ToLower <> ".htm" Then
                    Response.Write(" ðà äëðñ ÷åáõ îúàéí (.jpg,jpeg,bmp,gif,htm,html)")
                    Exit Sub

                Else

                    upldimg(imgName, imgExt)

                End If

            End If
        Else


            Dim imgExt As String = Image1.ImageUrl.Split("/assets/")(4)

            img = imgext


        End If
</code>

 
Old February 5th, 2004, 02:45 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI,

I found my problem. Instead of using Functions i used Subs.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning Automatic Variables from Functions jabney BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 2 November 29th, 2008 09:56 PM
Can variables be pulled out of functions Apocolypse2005 Javascript How-To 3 July 21st, 2006 05:16 PM
Help with functions and variables DeadlyDesigns.NET Beginning PHP 6 January 26th, 2005 12:28 AM
Help needed with variables and functions interrupt Javascript How-To 2 May 24th, 2004 08:47 AM
Global variables and functions madhukp ASP.NET 1.x and 2.0 Application Design 3 October 9th, 2003 09:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.