Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Wednesday, March 28, 2012

Substring

Hello

I have the following string:

myName = "John Smith Curtis"

I want to get the first word, i.e. "John", which means I want to get everything from the start to the first space.

I know I should use Substring but I don't know what to do to remove the first word.

Thanks,
Miguelstring myName = "John Smith Curtis";
myName = myName.Substring( 0, myName.IndexOf( " " ) );

The best way to go though would be to do

myName.Split(" ")(0) -> That will return the first element before the space

If you really want to us substring then do

myName.Substring(0,4)


myName.Remove(myName.IndexOf(' ')) will return "John"


try the following ( i didnt check for going out of bound to keep the example simple)

string myName = "John Smith Curtis";

//get the index of the frist space
int index = myName.IndexOf(" ");

//get the first word
string firstname = myName.Substring(0, index);

//remove the first word
myName = myName.Remove(0, index + 1);

Subtracting Date in VB.Net

Need Help!

How do I write the following expression for my project limiting the number of entries on my datagrid by 30 days from Now():

<!--

SELECT * FROM tblGrid WHERE dateEntered between Now() - 30 and Now()

-->

note: dateEntered are the dates in my date field (mm-dd-yyyy)

Thanks a lot.

If you are using VB.NET, you can use DateTime.Add method. There's an exampe in the docs here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclassaddtopic.asp

Monday, March 26, 2012

Suggestion regarding Top/footer includes

Hello,

I have the following situation. On all of my pages I would like to include a top and footer ascx file. Therefore I created two user controls. Now the the top.ascx contains another usercontrol which is a menu and shown in a table and each link in that menu is seperated with a line break. Somethin like this:

link1
link2
link3
...

Now this menu is in a table. The table looks like this:

<table width="100%">
<tbody>
<tr valign="top">
<td width="15%">
MENU HERE
</td>
<td>
CONTENT WILL BE HERE
</td>
</tr>
</tbody>
</table
Now I need to get rid of everything what comes after the MENU HERE <TD>, because this will be used for my main content. and the table will be closed then in the footer. However webmatrix always adds the missing html tags and therefore my table always looks like shown above. I hope that you guys understand what I mean. Is there anything I can do or is this is the wrong way?

ThanksI recommend that you use MasterPages, where you place the footer/header in that template.

Regards.
Arent MasterPages only in 2.0? I am using 1.1.
Nop, try to download this forum code and see how master pages are being used.

regards.
Thanks haider_balal,

I can imagine that the code for this forum is complicated and that it contains a lot of stuff. Isnt there an easier article which explains master pages in 1.1?
Hello, try to check this and give me your opinion:

MasterPages Templating Framework

regards.
2.0 will be so much fun
Why wait till asp.net 2.0 ? We can still use it in 1.1 !!!!!

regards.

Suggestions for ASP.NET Data Repeater

Right. Any suggestions on how to layout data to look like the following? I tried using a a web user control with a repeater in it, and for each different location create a new user web control and bind only the establishments applicable to that location to that repeater... but for some reason the repeaters or any other data controls aren't instantiated inside the web user control. Total pain in the bum.

The salient fields in the Establishments table in relation to the image are:
ID, Name, Area

The ID is just the ID for each establishment, the name is the name (e.g. "Arklow Bay Confer...", "Glenart Castle Hotel", "Ballyknocked Coun..." etc. etc."), and the Area (e.g. Arklow, Ashford, Aughrim, Blessington).

Any thoughts on how I could design my Repeater or Grid etc to display everything, but to group by the Area field as in the image?This is coming from a database, correct? And you have control over the recordset that is returned?
Absolute and complete control yes
Have two datatables filled up in your dataset.

First:

EstablishmentID+LongName

Second:

EstablishmentID+Area

You can then add a relationship between them, and bind it to the repeater. Styling it as you wish of course.

Here's an example:
http://support.microsoft.com/default.aspx?scid=kb;en-us;326338
Cool thanks I'll have a look at that!
Post your code when it works. It's helpful for searches. :)
Didn't take too much tinkering to get it working. I'll post a fuller example in a little while...

<asp:Repeater id="parentRepeater" runat="server">
<itemtemplate>
<b>
<%#DataBinder.Eval(Container.DataItem, "[Area Name]")%>
</b>
<br>
<asp:Repeater id="childRepeater" runat="server" datasource='<%#Container.DataItem.Row.GetChildRows("myrelation")%>'>
<itemtemplate>
<%#Container.DataItem("Name")%><br>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnn As SqlConnection = New SqlConnection("Data Source=localhost;Initial Catalog=SomeDB;Integrated Security=True;Pooling=False")
Dim cmd1 As SqlDataAdapter = New SqlDataAdapter("select * from areas", cnn)
Dim ds As DataSet = New DataSet()
cmd1.Fill(ds, "areas")

Dim cmd2 As SqlDataAdapter = New SqlDataAdapter("select * from establishments", cnn)
cmd2.Fill(ds, "establishments")

ds.Relations.Add("myrelation", ds.Tables("areas").Columns(0), ds.Tables("establishments").Columns(14))
parentRepeater.DataSource = ds.Tables("areas")

Page.DataBind()
cnn.Close()
End Sub

Saturday, March 24, 2012

Sum of XML data

I am reading an XML file and writing its contents to a Repeater control using the following code:

Dim dstTS As DataSet

dstTS = New DataSet()
dstTS.ReadXml( MapPath( "cw052004.xml" ) )

rptTS.DataSource = dstTS
rptTS.DataBind()

It works fine. However, I would also like to calculate the sum of a the "item_cost" from each node in the XML file and place it in a variable.

Can anybody suggest the best way to go about this?do some searching for examples on the itemdatabound event. this is fired everytime an item is bound and you can use this to sum up your grids and such.
Awesome, thanks!

Thursday, March 22, 2012

Suppress Crystal Reports Section in VB .Net 2003

Hello everyone. When I had VS .Net 2002, I could use the following code to suppress a section in my crystal report.crpt.Section6.SectionFormat.EnableSuppress = True
Now that I have moved to plain VB .Net 2003 with Crystal Reports 10, this command will not work.

Anyone know the correct syntax for this line in VB .Net for Crystal 10?

Here is my initial code in my web page.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO

Dim crpt As New ReportDocument

crpt.Load("C:\inetpub\wwwroot\McClure\CigUnitsRpt.rpt")

ThanksBump
For anyone interested, this is the way to do it with VB .Net 2003 and Crystal 10
dim crpt as New ReortDocument()
crpt.Load("PathAndFileName")
crpt.ReportDefinition.Sections(6).SectionFormat.EnableSuppress = True

Tuesday, March 13, 2012

switch statement

I have the following switch statement and am getting the error:
not all code paths return a value
I am not seeing why.

publicbool checkNewMove(ArrayList myArray,int myInt)

{

switch (myInt)

{

case 4 :

if( System.Convert.ToInt32( myArray[13] ) == 0 &&

System.Convert.ToInt32( myArrayMusic [8] ) == 1 )

{

myArrayMusic [8] = 0;

myArray[4] = 0;

myArray[13] = 1;

pNum = 4;

tempAL = myArray;

printArray(tempAL);

bSuccess =true;

break;

}

break;

default :

{

bSuccess =false;

//return bSuccess;

break;

}

//break;

}// end switch


}
Suggestions?
Thanks,
ZathI have added the line you are missing in red

publicbool checkNewMove(ArrayList myArray,int myInt)
{
switch (myInt)
{
case 4 :
if( System.Convert.ToInt32( myArray[13] ) == 0 &&
System.Convert.ToInt32( myArray[WhateverNumberThisIsSupposedToBe] ) == 1 )
{
myArray[WhateverNumberThisIsSupposedToBe] = 0;
myArray[4] = 0;
myArray[13] = 1;
pNum = 4;
tempAL = myArray;
printArray(tempAL);
bSuccess =true;
break;
}
break;
default :
{
bSuccess =false;
//return bSuccess;
break;
}
}// end switch
return bSuccess; [EDIT]
}


Thanks. don't know why I didn't see that. I have written many functions that need a return.
Must have been I was looking too hard at the switch.
Zath

switch statement error?

This is my first application so be gentle. :) I'm using WebMatrix.
I have the following code in index.aspx

<script runat="server">
switch(Request.QueryString["page"]) {
case "products":
masterForm.Controls.Add(LoadControl("products.ascx"));
break;
}
</script
masterForm is the id of the form tag in index.aspx

I am basically trying to dynamically include each section and use index.aspx as the master template file.

Here's the error:
Compiler Error Message: CS1519: Invalid token 'switch' in class, struct, or interface member declaration

It's stopping on the line with the switch statement.

What am I doing wrong?what is "page" in the following code

switch(Request.QueryString["page"])


page is supposed to be coming from:

index.aspx?page=products
ok I think the problem is that you are declaring switch in the HTML View. You need to run this code in the code behind file where all the Page_Load and Page_Init methods are. I hope you understand what I am trying to say.
Thanks, that did it!


<script runat="server">
void Page_Load() {
switch(Request.QueryString["page"]) {
case "products":
masterForm.Controls.Add(LoadControl("products.ascx"));
break;
}
}
</script>

Mohammed, WebMatrix doesn't permit the use of CodeBehind.

grizjr, you need to place the switch in the Page_Load method. For example:

 void Page_Load(Object Sender, EventArgs E) {

switch (...) {
...
}
}

Obviously you've decided against my suggestion of simplifying your code.
The code is not working properly.
<script runat="server">

void Page_Load() {

switch(Request.QueryString["page"]) {

case "products":

masterForm.Controls.Add(LoadControl("products.ascx"));

break;

}

}

</script>
When I try and run it: I get this message:

Active Server Pages-Error 'ASP 0124'

Missing Language attribute

/nbhs/control-panel/switch.asp, line 2

The required Language attribute of the script tag is missing.

Active Server Pages-Error 'ASP 0124'


What tag is it missing?Tongue Tied [:S]


Now that problem is fixed with this line of code:
<script language="vbscript" runat="server">
I just needed to add language="vbscript"
now I get another problem
This is the code that I have:
<script language="vbscript" runat="server">

void Page_Load(Object Sender, EventArgs E) {
switch(Request.QueryString["page"]) {

case "products":

masterForm.Controls.Add(LoadControl("products.ascx"));

break;

}

}

</script>

The error that I get is this:


Microsoft VBScript compilation error-Error '800a03ee'

Expected ')'

/nbhs/control-panel/switch.asp, line 5

void Page_Load(Object Sender, EventArgs E) {
--------^

How can I fix this?