radyokafa radyokafa - 6 months ago 49
Vb.net Question

local variable 'request' cannot be referred to before it is declared

<%@ import Namespace="ECozum.HPM.Helper.Models" %>
<%@ import Namespace="ECozum.HPM.Helper" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Collections.Generic" %>
<%@ import Namespace="System.Linq" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.Mvc" %>
<%@ import Namespace="HPMSample" %>
<%@ import Namespace="Newtonsoft.Json" %>
<%@ import Namespace="Newtonsoft.Json.Linq" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Web.Script.Serialization" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data.SqlClient.SqlCommand" %>
<%@ import Namespace="System.Data.SqlClient.SqlDataAdapter" %>
<!--#include file ="conn_kontrol.ascx"-->

<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="utf-8" Inherits="System.Web.Mvc.ViewPage" validateRequest="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<%
dim tutar = 0.0000
dim OGRENCI_ID = 0
tutar = Request.QueryString("tutar") ' ERROR HERE ******
OGRENCI_ID = Request.QueryString("OGRENCI_ID")


Dim cdata = New ECozum.HPM.Helper.Models.CustomData()
cdata.Id = "1"
cdata.Value = OGRENCI_ID
cdata.Visible = 1
cdata.Editable = 1



Dim list = New List(Of ECozum.HPM.Helper.Models.CustomData)
list.Add(cdata)




Dim request = New HttpPostRequestMessage() With { _
.User = New User() With { _
.Verify = 1, _
.VerifyFailAct = 1, _
.Id = 2 _
}, _
.Order = New Order() With { _
.DateTime = DateTime.UtcNow.ToString("u"), _
.Reference = Guid.NewGuid().ToString() _
}, _
.Payment = New Payment() With { _
.CData = list, _
.Method = New List(Of Integer)() From { _
-1 _
}, _
.Amount = tutar, _
.AmntEdit = 1, _
.SuccessUrl = "http://localhost:50/sonuc.aspx?s=basarili", _
.FailUrl = "http://localhost:50/sonuc.aspx?s=basarisiz", _
.ReturnUrl = "http://localhost:50/sonuc.aspx?s=return" _
}, _
.HashMethod = CInt(Hash.HashType.HMACSHA256) _
}





ViewBag.HPMForm = HPMHelper.BuildForm(request, "http://hpm.netahsilatdemo.com/hpm", "netahsilat")


%><div><%=ViewBag.HPMForm%></div>
<form name="form1" id="form1">
</form>
</body>
</html>


at that page
i get this error:
"local variable 'request' cannot be referred to before it is declared"
at that line:

tutar = Request.QueryString("tutar")


can someone help me please? i looked at the other posts about similar problems but cant figured out...

Answer

Dim request = New HttpPostRequestMessage() change this line. Use any random name like 'requestobject' or 'rnd123'. Since you have it declared as a variable, it is conflicting with default request object.

Comments